Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1 | /* GStreamer |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 2 | * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this library; if not, write to the |
| 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 17 | * Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
Benjamin Otte | 90da904 | 2003-06-29 19:46:12 +0000 | [diff] [blame] | 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include "config.h" |
| 22 | #endif |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 23 | #include <string.h> |
Wim Taymans | 17d464c | 2004-10-26 17:59:18 +0000 | [diff] [blame^] | 24 | #include <math.h> |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 25 | |
| 26 | /* First, include the header file for the plugin, to bring in the |
| 27 | * object definition and other useful things. |
| 28 | */ |
| 29 | #include "gstdvdec.h" |
| 30 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 31 | #define NTSC_HEIGHT 480 |
| 32 | #define NTSC_BUFFER 120000 |
David Schleef | ce51f61 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 33 | #define NTSC_FRAMERATE 29.997 |
| 34 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 35 | #define PAL_HEIGHT 576 |
| 36 | #define PAL_BUFFER 144000 |
David Schleef | ce51f61 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 37 | #define PAL_FRAMERATE 25.0 |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 38 | |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 39 | #define PAL_NORMAL_PAR_X 16 |
| 40 | #define PAL_NORMAL_PAR_Y 15 |
| 41 | #define PAL_WIDE_PAR_X 64 |
| 42 | #define PAL_WIDE_PAR_Y 45 |
| 43 | |
| 44 | #define NTSC_NORMAL_PAR_X 80 |
| 45 | #define NTSC_NORMAL_PAR_Y 89 |
| 46 | #define NTSC_WIDE_PAR_X 320 |
| 47 | #define NTSC_WIDE_PAR_Y 267 |
| 48 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 49 | /* The ElementDetails structure gives a human-readable description |
| 50 | * of the plugin, as well as author and version data. |
| 51 | */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 52 | static GstElementDetails dvdec_details = |
| 53 | GST_ELEMENT_DETAILS ("DV (smpte314) decoder plugin", |
| 54 | "Codec/Decoder/Video", |
| 55 | "Uses libdv to decode DV video (libdv.sourceforge.net)", |
| 56 | "Erik Walthinsen <omega@cse.ogi.edu>\n" "Wim Taymans <wim.taymans@tvd.be>"); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 57 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 58 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 59 | /* These are the signals that this element can fire. They are zero- |
| 60 | * based because the numbers themselves are private to the object. |
| 61 | * LAST_SIGNAL is used for initialization of the signal array. |
| 62 | */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 63 | enum |
| 64 | { |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 65 | /* FILL ME */ |
| 66 | LAST_SIGNAL |
| 67 | }; |
| 68 | |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 69 | #define DV_DEFAULT_QUALITY DV_QUALITY_BEST |
| 70 | #define DV_DEFAULT_DECODE_NTH 1 |
| 71 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 72 | /* Arguments are identified the same way, but cannot be zero, so you |
| 73 | * must leave the ARG_0 entry in as a placeholder. |
| 74 | */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 75 | enum |
| 76 | { |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 77 | ARG_0, |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 78 | ARG_CLAMP_LUMA, |
| 79 | ARG_CLAMP_CHROMA, |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 80 | ARG_QUALITY, |
| 81 | ARG_DECODE_NTH |
Stéphane Loeuillet | 4c89978 | 2004-05-21 23:28:57 +0000 | [diff] [blame] | 82 | /* FILL ME */ |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 85 | const gint qualities[] = { |
| 86 | DV_QUALITY_DC, |
| 87 | DV_QUALITY_AC_1, |
| 88 | DV_QUALITY_AC_2, |
| 89 | DV_QUALITY_DC | DV_QUALITY_COLOR, |
| 90 | DV_QUALITY_AC_1 | DV_QUALITY_COLOR, |
Stéphane Loeuillet | 4c89978 | 2004-05-21 23:28:57 +0000 | [diff] [blame] | 91 | DV_QUALITY_AC_2 | DV_QUALITY_COLOR |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 94 | /* The PadFactory structures describe what pads the element has or |
| 95 | * can have. They can be quite complex, but for this dvdec plugin |
| 96 | * they are rather simple. |
| 97 | */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 98 | static GstStaticPadTemplate sink_temp = GST_STATIC_PAD_TEMPLATE ("sink", |
| 99 | GST_PAD_SINK, |
| 100 | GST_PAD_ALWAYS, |
| 101 | GST_STATIC_CAPS ("video/x-dv, systemstream = (boolean) true") |
| 102 | ); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 103 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 104 | static GstStaticPadTemplate video_src_temp = GST_STATIC_PAD_TEMPLATE ("video", |
| 105 | GST_PAD_SRC, |
| 106 | GST_PAD_ALWAYS, |
| 107 | GST_STATIC_CAPS ("video/x-raw-yuv, " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 108 | "format = (fourcc) YUY2, " |
| 109 | "width = (int) 720, " |
| 110 | "height = (int) { " |
| 111 | G_STRINGIFY (NTSC_HEIGHT) ", " G_STRINGIFY (PAL_HEIGHT) |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 112 | " }, " |
| 113 | "pixel-aspect-ratio=(fraction) { " |
| 114 | G_STRINGIFY (PAL_NORMAL_PAR_X) "/" G_STRINGIFY (PAL_NORMAL_PAR_Y) "," |
| 115 | G_STRINGIFY (PAL_WIDE_PAR_X) "/" G_STRINGIFY (PAL_WIDE_PAR_Y) "," |
| 116 | G_STRINGIFY (NTSC_NORMAL_PAR_X) "/" G_STRINGIFY (NTSC_NORMAL_PAR_Y) "," |
| 117 | G_STRINGIFY (NTSC_WIDE_PAR_X) "/" G_STRINGIFY (NTSC_WIDE_PAR_Y) "}," |
| 118 | "framerate = (double) [ 1.0, 60.0 ];" |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 119 | //"framerate = (double) { " |
| 120 | //G_STRINGIFY (PAL_FRAMERATE) ", " G_STRINGIFY (NTSC_FRAMERATE) |
| 121 | //" }; " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 122 | "video/x-raw-rgb, " |
| 123 | "bpp = (int) 32, " |
| 124 | "depth = (int) 32, " |
| 125 | "endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", " |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 126 | "red_mask = (int) 0x00ff0000, " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 127 | "green_mask = (int) 0x0000ff00, " |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 128 | "blue_mask = (int) 0x000000ff, " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 129 | "width = (int) 720, " |
| 130 | "height = (int) { " |
| 131 | G_STRINGIFY (NTSC_HEIGHT) ", " G_STRINGIFY (PAL_HEIGHT) |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 132 | " }, " |
| 133 | "pixel-aspect-ratio=(fraction) { " |
| 134 | G_STRINGIFY (PAL_NORMAL_PAR_X) "/" G_STRINGIFY (PAL_NORMAL_PAR_Y) "," |
| 135 | G_STRINGIFY (PAL_WIDE_PAR_X) "/" G_STRINGIFY (PAL_WIDE_PAR_Y) "," |
| 136 | G_STRINGIFY (NTSC_NORMAL_PAR_X) "/" G_STRINGIFY (NTSC_NORMAL_PAR_Y) "," |
| 137 | G_STRINGIFY (NTSC_WIDE_PAR_X) "/" G_STRINGIFY (NTSC_WIDE_PAR_Y) "}," |
| 138 | "framerate = (double) [ 1.0, 60.0 ];" |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 139 | //"framerate = (double) { " |
| 140 | //G_STRINGIFY (PAL_FRAMERATE) ", " G_STRINGIFY (NTSC_FRAMERATE) |
| 141 | //" }; " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 142 | "video/x-raw-rgb, " |
| 143 | "bpp = (int) 24, " |
| 144 | "depth = (int) 24, " |
| 145 | "endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", " |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 146 | "red_mask = (int) 0x00ff0000, " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 147 | "green_mask = (int) 0x0000ff00, " |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 148 | "blue_mask = (int) 0x000000ff, " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 149 | "width = (int) 720, " |
| 150 | "height = (int) { " |
| 151 | G_STRINGIFY (NTSC_HEIGHT) ", " G_STRINGIFY (PAL_HEIGHT) |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 152 | " }, " |
| 153 | "pixel-aspect-ratio=(fraction) { " |
| 154 | G_STRINGIFY (PAL_NORMAL_PAR_X) "/" G_STRINGIFY (PAL_NORMAL_PAR_Y) "," |
| 155 | G_STRINGIFY (PAL_WIDE_PAR_X) "/" G_STRINGIFY (PAL_WIDE_PAR_Y) "," |
| 156 | G_STRINGIFY (NTSC_NORMAL_PAR_X) "/" G_STRINGIFY (NTSC_NORMAL_PAR_Y) "," |
| 157 | G_STRINGIFY (NTSC_WIDE_PAR_X) "/" G_STRINGIFY (NTSC_WIDE_PAR_Y) "}," |
| 158 | "framerate = (double) [ 1.0, 60.0 ]" |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 159 | //"framerate = (double) { " |
| 160 | //G_STRINGIFY (PAL_FRAMERATE) ", " G_STRINGIFY (NTSC_FRAMERATE) |
| 161 | //" }" |
| 162 | ) |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 163 | ); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 164 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 165 | static GstStaticPadTemplate audio_src_temp = GST_STATIC_PAD_TEMPLATE ("audio", |
| 166 | GST_PAD_SRC, |
| 167 | GST_PAD_ALWAYS, |
| 168 | GST_STATIC_CAPS ("audio/x-raw-int, " |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 169 | "depth = (int) 16, " |
| 170 | "width = (int) 16, " |
| 171 | "signed = (boolean) TRUE, " |
| 172 | "channels = (int) 2, " |
| 173 | "endianness = (int) " G_STRINGIFY (G_LITTLE_ENDIAN) ", " |
| 174 | "rate = (int) [ 4000, 48000 ]") |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 175 | ); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 176 | |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 177 | #define GST_TYPE_DVDEC_QUALITY (gst_dvdec_quality_get_type()) |
| 178 | GType |
| 179 | gst_dvdec_quality_get_type (void) |
| 180 | { |
| 181 | static GType qtype = 0; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 182 | |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 183 | if (qtype == 0) { |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 184 | static const GEnumValue values[] = { |
| 185 | {0, "DV_QUALITY_FASTEST", "Fastest decoding, low-quality mono"}, |
| 186 | {1, "DV_QUALITY_AC_1", "Mono decoding using the first AC coefficient"}, |
| 187 | {2, "DV_QUALITY_AC_2", "Highest quality mono decoding"}, |
| 188 | {3, "DV_QUALITY_DC|DV_QUALITY_COLOUR", "Fastest colour decoding"}, |
| 189 | {4, "DV_QUALITY_AC_1|DV_QUALITY_COLOUR", |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 190 | "Colour, using only the first AC coefficient"}, |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 191 | {5, "DV_QUALITY_BEST", "Highest quality colour decoding"}, |
Johan Dahlin | 92be8f9 | 2004-05-19 09:21:43 +0000 | [diff] [blame] | 192 | {0, NULL, NULL}, |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 193 | }; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 194 | |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 195 | qtype = g_enum_register_static ("GstDVDecQualityEnum", values); |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 196 | } |
| 197 | return qtype; |
| 198 | } |
| 199 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 200 | /* A number of functon prototypes are given so we can refer to them later. */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 201 | static void gst_dvdec_base_init (gpointer g_class); |
| 202 | static void gst_dvdec_class_init (GstDVDecClass * klass); |
| 203 | static void gst_dvdec_init (GstDVDec * dvdec); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 204 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 205 | static const GstQueryType *gst_dvdec_get_src_query_types (GstPad * pad); |
| 206 | static gboolean gst_dvdec_src_query (GstPad * pad, GstQueryType type, |
| 207 | GstFormat * format, gint64 * value); |
| 208 | static const GstFormat *gst_dvdec_get_formats (GstPad * pad); |
| 209 | static gboolean gst_dvdec_sink_convert (GstPad * pad, GstFormat src_format, |
| 210 | gint64 src_value, GstFormat * dest_format, gint64 * dest_value); |
| 211 | static gboolean gst_dvdec_src_convert (GstPad * pad, GstFormat src_format, |
| 212 | gint64 src_value, GstFormat * dest_format, gint64 * dest_value); |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 213 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 214 | static GstPadLinkReturn gst_dvdec_video_link (GstPad * pad, |
| 215 | const GstCaps * caps); |
| 216 | static GstCaps *gst_dvdec_video_getcaps (GstPad * pad); |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 217 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 218 | static const GstEventMask *gst_dvdec_get_event_masks (GstPad * pad); |
| 219 | static gboolean gst_dvdec_handle_src_event (GstPad * pad, GstEvent * event); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 220 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 221 | static void gst_dvdec_loop (GstElement * element); |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 222 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 223 | static GstElementStateReturn gst_dvdec_change_state (GstElement * element); |
| 224 | |
| 225 | static void gst_dvdec_set_property (GObject * object, guint prop_id, |
| 226 | const GValue * value, GParamSpec * pspec); |
| 227 | static void gst_dvdec_get_property (GObject * object, guint prop_id, |
| 228 | GValue * value, GParamSpec * pspec); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 229 | |
| 230 | /* The parent class pointer needs to be kept around for some object |
| 231 | * operations. |
| 232 | */ |
| 233 | static GstElementClass *parent_class = NULL; |
| 234 | |
| 235 | /* This array holds the ids of the signals registered for this object. |
| 236 | * The array indexes are based on the enum up above. |
| 237 | */ |
Andy Wingo | d625815 | 2002-03-19 04:10:05 +0000 | [diff] [blame] | 238 | /*static guint gst_dvdec_signals[LAST_SIGNAL] = { 0 }; */ |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 239 | |
| 240 | /* This function is used to register and subsequently return the type |
| 241 | * identifier for this object class. On first invocation, it will |
| 242 | * register the type, providing the name of the class, struct sizes, |
| 243 | * and pointers to the various functions that define the class. |
| 244 | */ |
| 245 | GType |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 246 | gst_dvdec_get_type (void) |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 247 | { |
| 248 | static GType dvdec_type = 0; |
| 249 | |
| 250 | if (!dvdec_type) { |
| 251 | static const GTypeInfo dvdec_info = { |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 252 | sizeof (GstDVDecClass), |
| 253 | gst_dvdec_base_init, |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 254 | NULL, |
| 255 | (GClassInitFunc) gst_dvdec_class_init, |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 256 | NULL, |
| 257 | NULL, |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 258 | sizeof (GstDVDec), |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 259 | 0, |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 260 | (GInstanceInitFunc) gst_dvdec_init, |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 261 | }; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 262 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 263 | dvdec_type = |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 264 | g_type_register_static (GST_TYPE_ELEMENT, "GstDVDec", &dvdec_info, 0); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 265 | } |
| 266 | return dvdec_type; |
| 267 | } |
| 268 | |
Jan Schmidt | c4ec05b | 2003-11-02 03:32:31 +0000 | [diff] [blame] | 269 | static void |
| 270 | gst_dvdec_base_init (gpointer g_class) |
| 271 | { |
| 272 | GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); |
| 273 | |
| 274 | /* The pad templates can be easily generated from the factories above, |
| 275 | * and then added to the list of padtemplates for the elementfactory. |
| 276 | * Note that the generated padtemplates are stored in static global |
| 277 | * variables, for the gst_dvdec_init function to use later on. |
| 278 | */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 279 | gst_element_class_add_pad_template (element_class, |
| 280 | gst_static_pad_template_get (&sink_temp)); |
| 281 | gst_element_class_add_pad_template (element_class, |
| 282 | gst_static_pad_template_get (&video_src_temp)); |
| 283 | gst_element_class_add_pad_template (element_class, |
| 284 | gst_static_pad_template_get (&audio_src_temp)); |
Jan Schmidt | c4ec05b | 2003-11-02 03:32:31 +0000 | [diff] [blame] | 285 | |
| 286 | gst_element_class_set_details (element_class, &dvdec_details); |
| 287 | } |
| 288 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 289 | /* In order to create an instance of an object, the class must be |
| 290 | * initialized by this function. GObject will take care of running |
| 291 | * it, based on the pointer to the function provided above. |
| 292 | */ |
| 293 | static void |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 294 | gst_dvdec_class_init (GstDVDecClass * klass) |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 295 | { |
| 296 | /* Class pointers are needed to supply pointers to the private |
| 297 | * implementations of parent class methods. |
| 298 | */ |
| 299 | GObjectClass *gobject_class; |
| 300 | GstElementClass *gstelement_class; |
| 301 | |
| 302 | /* Since the dvdec class contains the parent classes, you can simply |
| 303 | * cast the pointer to get access to the parent classes. |
| 304 | */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 305 | gobject_class = (GObjectClass *) klass; |
| 306 | gstelement_class = (GstElementClass *) klass; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 307 | |
| 308 | /* The parent class is needed for class method overrides. */ |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 309 | parent_class = g_type_class_ref (GST_TYPE_ELEMENT); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 310 | |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 311 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_LUMA, |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 312 | g_param_spec_boolean ("clamp_luma", "Clamp luma", "Clamp luma", |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 313 | FALSE, G_PARAM_READWRITE)); |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 314 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_CHROMA, |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 315 | g_param_spec_boolean ("clamp_chroma", "Clamp chroma", "Clamp chroma", |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 316 | FALSE, G_PARAM_READWRITE)); |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 317 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY, |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 318 | g_param_spec_enum ("quality", "Quality", "Decoding quality", |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 319 | GST_TYPE_DVDEC_QUALITY, DV_DEFAULT_QUALITY, G_PARAM_READWRITE)); |
| 320 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DECODE_NTH, |
| 321 | g_param_spec_int ("drop-factor", "Drop Factor", "Only decode Nth frame", |
| 322 | 1, G_MAXINT, DV_DEFAULT_DECODE_NTH, G_PARAM_READWRITE)); |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 323 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 324 | gobject_class->set_property = gst_dvdec_set_property; |
| 325 | gobject_class->get_property = gst_dvdec_get_property; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 326 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 327 | gstelement_class->change_state = gst_dvdec_change_state; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 328 | |
Andy Wingo | d625815 | 2002-03-19 04:10:05 +0000 | [diff] [blame] | 329 | /* table initialization, only do once */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 330 | dv_init (0, 0); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /* This function is responsible for initializing a specific instance of |
| 334 | * the plugin. |
| 335 | */ |
| 336 | static void |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 337 | gst_dvdec_init (GstDVDec * dvdec) |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 338 | { |
Wim Taymans | ce3fd0b | 2002-06-13 22:30:15 +0000 | [diff] [blame] | 339 | gint i; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 340 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 341 | dvdec->found_header = FALSE; |
Wim Taymans | ce3fd0b | 2002-06-13 22:30:15 +0000 | [diff] [blame] | 342 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 343 | dvdec->sinkpad = |
| 344 | gst_pad_new_from_template (gst_static_pad_template_get (&sink_temp), |
| 345 | "sink"); |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 346 | gst_pad_set_query_function (dvdec->sinkpad, NULL); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 347 | gst_pad_set_convert_function (dvdec->sinkpad, |
| 348 | GST_DEBUG_FUNCPTR (gst_dvdec_sink_convert)); |
| 349 | gst_pad_set_formats_function (dvdec->sinkpad, |
| 350 | GST_DEBUG_FUNCPTR (gst_dvdec_get_formats)); |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 351 | gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 352 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 353 | dvdec->videosrcpad = |
| 354 | gst_pad_new_from_template (gst_static_pad_template_get (&video_src_temp), |
| 355 | "video"); |
| 356 | gst_pad_set_query_function (dvdec->videosrcpad, |
| 357 | GST_DEBUG_FUNCPTR (gst_dvdec_src_query)); |
| 358 | gst_pad_set_query_type_function (dvdec->videosrcpad, |
| 359 | GST_DEBUG_FUNCPTR (gst_dvdec_get_src_query_types)); |
| 360 | gst_pad_set_event_function (dvdec->videosrcpad, |
| 361 | GST_DEBUG_FUNCPTR (gst_dvdec_handle_src_event)); |
| 362 | gst_pad_set_event_mask_function (dvdec->videosrcpad, |
| 363 | GST_DEBUG_FUNCPTR (gst_dvdec_get_event_masks)); |
| 364 | gst_pad_set_convert_function (dvdec->videosrcpad, |
| 365 | GST_DEBUG_FUNCPTR (gst_dvdec_src_convert)); |
| 366 | gst_pad_set_formats_function (dvdec->videosrcpad, |
| 367 | GST_DEBUG_FUNCPTR (gst_dvdec_get_formats)); |
| 368 | gst_pad_set_getcaps_function (dvdec->videosrcpad, |
| 369 | GST_DEBUG_FUNCPTR (gst_dvdec_video_getcaps)); |
| 370 | gst_pad_set_link_function (dvdec->videosrcpad, |
| 371 | GST_DEBUG_FUNCPTR (gst_dvdec_video_link)); |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 372 | gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->videosrcpad); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 373 | |
| 374 | dvdec->audiosrcpad = |
| 375 | gst_pad_new_from_template (gst_static_pad_template_get (&audio_src_temp), |
| 376 | "audio"); |
| 377 | gst_pad_set_query_function (dvdec->audiosrcpad, |
| 378 | GST_DEBUG_FUNCPTR (gst_dvdec_src_query)); |
| 379 | gst_pad_set_query_type_function (dvdec->audiosrcpad, |
| 380 | GST_DEBUG_FUNCPTR (gst_dvdec_get_src_query_types)); |
| 381 | gst_pad_set_event_function (dvdec->audiosrcpad, |
| 382 | GST_DEBUG_FUNCPTR (gst_dvdec_handle_src_event)); |
| 383 | gst_pad_set_event_mask_function (dvdec->audiosrcpad, |
| 384 | GST_DEBUG_FUNCPTR (gst_dvdec_get_event_masks)); |
| 385 | gst_pad_set_convert_function (dvdec->audiosrcpad, |
| 386 | GST_DEBUG_FUNCPTR (gst_dvdec_src_convert)); |
| 387 | gst_pad_set_formats_function (dvdec->audiosrcpad, |
| 388 | GST_DEBUG_FUNCPTR (gst_dvdec_get_formats)); |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 389 | gst_pad_use_explicit_caps (dvdec->audiosrcpad); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 390 | gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->audiosrcpad); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 391 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 392 | gst_element_set_loop_function (GST_ELEMENT (dvdec), gst_dvdec_loop); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 393 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 394 | dvdec->bs = NULL; |
Wim Taymans | ce3fd0b | 2002-06-13 22:30:15 +0000 | [diff] [blame] | 395 | dvdec->length = 0; |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 396 | dvdec->next_ts = 0LL; |
Jan Schmidt | 0e0c2e5 | 2003-01-04 04:10:30 +0000 | [diff] [blame] | 397 | dvdec->end_position = -1LL; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 398 | dvdec->need_discont = FALSE; |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 399 | dvdec->new_media = FALSE; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 400 | dvdec->framerate = 0; |
| 401 | dvdec->height = 0; |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 402 | dvdec->frequency = 0; |
| 403 | dvdec->channels = 0; |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 404 | dvdec->wide = FALSE; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 405 | dvdec->drop_factor = 1; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 406 | |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 407 | dvdec->clamp_luma = FALSE; |
| 408 | dvdec->clamp_chroma = FALSE; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 409 | dvdec->quality = DV_DEFAULT_QUALITY; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 410 | dvdec->loop = FALSE; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 411 | |
| 412 | for (i = 0; i < 4; i++) { |
| 413 | dvdec->audio_buffers[i] = |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 414 | (gint16 *) g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16)); |
Wim Taymans | ce3fd0b | 2002-06-13 22:30:15 +0000 | [diff] [blame] | 415 | } |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 418 | static const GstFormat * |
| 419 | gst_dvdec_get_formats (GstPad * pad) |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 420 | { |
| 421 | static const GstFormat src_formats[] = { |
| 422 | GST_FORMAT_BYTES, |
Wim Taymans | ada49e5 | 2003-05-24 10:34:34 +0000 | [diff] [blame] | 423 | GST_FORMAT_DEFAULT, |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 424 | GST_FORMAT_TIME, |
| 425 | 0 |
| 426 | }; |
| 427 | static const GstFormat sink_formats[] = { |
| 428 | GST_FORMAT_BYTES, |
| 429 | GST_FORMAT_TIME, |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 430 | GST_FORMAT_DEFAULT, |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 431 | 0 |
| 432 | }; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 433 | |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 434 | return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 435 | } |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 436 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 437 | static gboolean |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 438 | gst_dvdec_src_convert (GstPad * pad, GstFormat src_format, gint64 src_value, |
| 439 | GstFormat * dest_format, gint64 * dest_value) |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 440 | { |
| 441 | gboolean res = TRUE; |
| 442 | GstDVDec *dvdec; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 443 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 444 | dvdec = GST_DVDEC (gst_pad_get_parent (pad)); |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 445 | if (dvdec->length == 0) |
| 446 | return FALSE; |
| 447 | |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 448 | if (dvdec->decoder == NULL) |
| 449 | return FALSE; |
| 450 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 451 | switch (src_format) { |
| 452 | case GST_FORMAT_BYTES: |
| 453 | switch (*dest_format) { |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 454 | case GST_FORMAT_BYTES: |
| 455 | *dest_value = src_value; |
| 456 | break; |
| 457 | case GST_FORMAT_DEFAULT: |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 458 | case GST_FORMAT_TIME: |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 459 | *dest_format = GST_FORMAT_TIME; |
| 460 | if (pad == dvdec->videosrcpad) |
| 461 | *dest_value = src_value * GST_SECOND / |
| 462 | (720 * dvdec->height * dvdec->bpp * dvdec->framerate / |
| 463 | GST_SECOND); |
| 464 | else if (pad == dvdec->audiosrcpad) |
| 465 | *dest_value = src_value * GST_SECOND / |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 466 | (2 * dvdec->frequency * dvdec->channels); |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 467 | break; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 468 | default: |
| 469 | res = FALSE; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 470 | } |
| 471 | break; |
| 472 | case GST_FORMAT_TIME: |
| 473 | switch (*dest_format) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 474 | case GST_FORMAT_BYTES: |
| 475 | if (pad == dvdec->videosrcpad) |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 476 | *dest_value = src_value * 720 * dvdec->height * dvdec->bpp * |
| 477 | dvdec->framerate / GST_SECOND; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 478 | else if (pad == dvdec->audiosrcpad) |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 479 | *dest_value = 2 * src_value * dvdec->frequency * |
| 480 | dvdec->channels / GST_SECOND; |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 481 | break; |
| 482 | case GST_FORMAT_TIME: |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 483 | case GST_FORMAT_DEFAULT: |
Jan Schmidt | 2d80a4a | 2004-05-13 11:32:42 +0000 | [diff] [blame] | 484 | *dest_format = GST_FORMAT_TIME; |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 485 | *dest_value = src_value; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 486 | break; |
| 487 | default: |
| 488 | res = FALSE; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 489 | } |
| 490 | break; |
| 491 | default: |
| 492 | res = FALSE; |
| 493 | } |
| 494 | return res; |
| 495 | } |
| 496 | |
| 497 | static gboolean |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 498 | gst_dvdec_sink_convert (GstPad * pad, GstFormat src_format, gint64 src_value, |
| 499 | GstFormat * dest_format, gint64 * dest_value) |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 500 | { |
| 501 | gboolean res = TRUE; |
| 502 | GstDVDec *dvdec; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 503 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 504 | dvdec = GST_DVDEC (gst_pad_get_parent (pad)); |
| 505 | |
| 506 | if (dvdec->length == 0) |
| 507 | return FALSE; |
| 508 | |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 509 | if (*dest_format == GST_FORMAT_DEFAULT) |
| 510 | *dest_format = GST_FORMAT_TIME; |
| 511 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 512 | switch (src_format) { |
| 513 | case GST_FORMAT_BYTES: |
| 514 | switch (*dest_format) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 515 | case GST_FORMAT_TIME: |
| 516 | { |
| 517 | guint64 frame; |
Wim Taymans | ada49e5 | 2003-05-24 10:34:34 +0000 | [diff] [blame] | 518 | |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 519 | /* get frame number */ |
| 520 | frame = src_value / dvdec->length; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 521 | |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 522 | *dest_value = (frame * GST_SECOND) / dvdec->framerate; |
| 523 | break; |
| 524 | } |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 525 | case GST_FORMAT_BYTES: |
| 526 | *dest_value = src_value; |
| 527 | break; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 528 | default: |
| 529 | res = FALSE; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 530 | } |
| 531 | break; |
| 532 | case GST_FORMAT_TIME: |
| 533 | switch (*dest_format) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 534 | case GST_FORMAT_BYTES: |
| 535 | { |
| 536 | guint64 frame; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 537 | |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 538 | /* calculate the frame */ |
| 539 | frame = src_value * dvdec->framerate / GST_SECOND; |
| 540 | /* calculate the offset */ |
| 541 | *dest_value = frame * dvdec->length; |
| 542 | break; |
| 543 | } |
Jan Schmidt | 4d97abb | 2004-05-21 13:28:24 +0000 | [diff] [blame] | 544 | case GST_FORMAT_TIME: |
| 545 | *dest_value = src_value; |
| 546 | break; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 547 | default: |
| 548 | res = FALSE; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 549 | } |
| 550 | break; |
| 551 | default: |
| 552 | res = FALSE; |
| 553 | } |
| 554 | return res; |
| 555 | } |
| 556 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 557 | static const GstQueryType * |
| 558 | gst_dvdec_get_src_query_types (GstPad * pad) |
| 559 | { |
Wim Taymans | 4d36ba7 | 2002-12-30 17:53:18 +0000 | [diff] [blame] | 560 | static const GstQueryType src_query_types[] = { |
| 561 | GST_QUERY_TOTAL, |
| 562 | GST_QUERY_POSITION, |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 563 | 0 |
| 564 | }; |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 565 | |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 566 | return src_query_types; |
| 567 | } |
| 568 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 569 | static gboolean |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 570 | gst_dvdec_src_query (GstPad * pad, GstQueryType type, |
| 571 | GstFormat * format, gint64 * value) |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 572 | { |
| 573 | gboolean res = TRUE; |
| 574 | GstDVDec *dvdec; |
| 575 | |
| 576 | dvdec = GST_DVDEC (gst_pad_get_parent (pad)); |
| 577 | |
| 578 | switch (type) { |
Wim Taymans | 4d36ba7 | 2002-12-30 17:53:18 +0000 | [diff] [blame] | 579 | case GST_QUERY_TOTAL: |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 580 | switch (*format) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 581 | default: |
| 582 | { |
| 583 | guint64 len; |
| 584 | GstFormat tmp_format; |
Wim Taymans | 9101d97 | 2002-06-15 22:30:58 +0000 | [diff] [blame] | 585 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 586 | if (!dvdec->bs) |
| 587 | return FALSE; |
| 588 | |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 589 | len = gst_bytestream_length (dvdec->bs); |
| 590 | tmp_format = GST_FORMAT_TIME; |
| 591 | if (len == -1 || !gst_pad_convert (dvdec->sinkpad, |
| 592 | GST_FORMAT_BYTES, len, &tmp_format, value)) { |
| 593 | return FALSE; |
| 594 | } |
| 595 | if (!gst_pad_convert (pad, GST_FORMAT_TIME, *value, format, value)) { |
| 596 | return FALSE; |
| 597 | } |
| 598 | break; |
| 599 | } |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 600 | } |
| 601 | break; |
Wim Taymans | 4d36ba7 | 2002-12-30 17:53:18 +0000 | [diff] [blame] | 602 | case GST_QUERY_POSITION: |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 603 | switch (*format) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 604 | default: |
| 605 | res = |
| 606 | gst_pad_convert (pad, GST_FORMAT_TIME, dvdec->next_ts, format, |
| 607 | value); |
| 608 | break; |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 609 | } |
| 610 | break; |
| 611 | default: |
| 612 | res = FALSE; |
| 613 | break; |
| 614 | } |
| 615 | return res; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 616 | } |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 617 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 618 | static const GstEventMask * |
| 619 | gst_dvdec_get_event_masks (GstPad * pad) |
| 620 | { |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 621 | static const GstEventMask src_event_masks[] = { |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 622 | {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH}, |
| 623 | {0,} |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 624 | }; |
| 625 | static const GstEventMask sink_event_masks[] = { |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 626 | {GST_EVENT_EOS, 0}, |
| 627 | {GST_EVENT_DISCONTINUOUS, 0}, |
| 628 | {GST_EVENT_FLUSH, 0}, |
| 629 | {0,} |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 630 | }; |
| 631 | |
| 632 | return (GST_PAD_IS_SRC (pad) ? src_event_masks : sink_event_masks); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 633 | } |
Wim Taymans | a7b776e | 2002-09-09 22:35:30 +0000 | [diff] [blame] | 634 | |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 635 | static gboolean |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 636 | gst_dvdec_handle_sink_event (GstDVDec * dvdec) |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 637 | { |
| 638 | guint32 remaining; |
| 639 | GstEvent *event; |
| 640 | GstEventType type; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 641 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 642 | gst_bytestream_get_status (dvdec->bs, &remaining, &event); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 643 | |
| 644 | type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN; |
| 645 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 646 | switch (type) { |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 647 | case GST_EVENT_FLUSH: |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 648 | case GST_EVENT_EOS: |
| 649 | case GST_EVENT_FILLER: |
Jan Schmidt | a6659f8 | 2004-06-07 13:25:14 +0000 | [diff] [blame] | 650 | { |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 651 | /* Forward the event to output sinks */ |
| 652 | if (GST_PAD_IS_LINKED (dvdec->videosrcpad)) { |
| 653 | gst_event_ref (event); |
| 654 | gst_pad_push (dvdec->videosrcpad, GST_DATA (event)); |
| 655 | } |
| 656 | if (GST_PAD_IS_LINKED (dvdec->audiosrcpad)) { |
| 657 | gst_event_ref (event); |
| 658 | gst_pad_push (dvdec->audiosrcpad, GST_DATA (event)); |
| 659 | } |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 660 | break; |
Jan Schmidt | a6659f8 | 2004-06-07 13:25:14 +0000 | [diff] [blame] | 661 | } |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 662 | case GST_EVENT_DISCONTINUOUS: |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 663 | { |
| 664 | gint i; |
| 665 | gboolean found = FALSE; |
| 666 | GstFormat format; |
| 667 | |
| 668 | format = GST_FORMAT_TIME; |
| 669 | /* try to get a timestamp from the discont formats */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 670 | for (i = 0; i < GST_EVENT_DISCONT_OFFSET_LEN (event); i++) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 671 | if (gst_pad_convert (dvdec->sinkpad, |
| 672 | GST_EVENT_DISCONT_OFFSET (event, i).format, |
| 673 | GST_EVENT_DISCONT_OFFSET (event, i).value, |
| 674 | &format, &dvdec->next_ts)) { |
| 675 | found = TRUE; |
| 676 | break; |
| 677 | } |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 678 | } |
| 679 | /* assume 0 then */ |
| 680 | if (!found) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 681 | dvdec->next_ts = 0LL; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 682 | } |
| 683 | dvdec->need_discont = TRUE; |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 684 | break; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 685 | } |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 686 | default: |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 687 | return gst_pad_event_default (dvdec->sinkpad, event); |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 688 | break; |
| 689 | } |
Wim Taymans | eebc284 | 2002-07-08 19:31:05 +0000 | [diff] [blame] | 690 | gst_event_unref (event); |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 691 | return TRUE; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 694 | static gboolean |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 695 | gst_dvdec_handle_src_event (GstPad * pad, GstEvent * event) |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 696 | { |
| 697 | gboolean res = TRUE; |
| 698 | GstDVDec *dvdec; |
| 699 | |
| 700 | dvdec = GST_DVDEC (gst_pad_get_parent (pad)); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 701 | |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 702 | switch (GST_EVENT_TYPE (event)) { |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 703 | case GST_EVENT_SEEK_SEGMENT: |
| 704 | { |
| 705 | gint64 position; |
| 706 | GstFormat format; |
| 707 | |
| 708 | /* first bring the format to time */ |
| 709 | format = GST_FORMAT_TIME; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 710 | if (!gst_pad_convert (pad, |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 711 | GST_EVENT_SEEK_FORMAT (event), |
| 712 | GST_EVENT_SEEK_ENDOFFSET (event), &format, &position)) { |
| 713 | /* could not convert seek format to time offset */ |
| 714 | res = FALSE; |
| 715 | break; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | dvdec->end_position = position; |
| 719 | dvdec->loop = GST_EVENT_SEEK_TYPE (event) & GST_SEEK_FLAG_SEGMENT_LOOP; |
| 720 | } |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 721 | case GST_EVENT_SEEK: |
| 722 | { |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 723 | gint64 position; |
| 724 | GstFormat format; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 725 | |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 726 | /* first bring the format to time */ |
| 727 | format = GST_FORMAT_TIME; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 728 | if (!gst_pad_convert (pad, |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 729 | GST_EVENT_SEEK_FORMAT (event), |
| 730 | GST_EVENT_SEEK_OFFSET (event), &format, &position)) { |
| 731 | /* could not convert seek format to time offset */ |
| 732 | res = FALSE; |
| 733 | break; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 734 | } |
Wim Taymans | ada49e5 | 2003-05-24 10:34:34 +0000 | [diff] [blame] | 735 | dvdec->next_ts = position; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 736 | /* then try to figure out the byteoffset for this time */ |
| 737 | format = GST_FORMAT_BYTES; |
| 738 | if (!gst_pad_convert (dvdec->sinkpad, GST_FORMAT_TIME, position, |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 739 | &format, &position)) { |
| 740 | /* could not convert seek format to byte offset */ |
| 741 | res = FALSE; |
| 742 | break; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 743 | } |
| 744 | /* seek to offset */ |
| 745 | if (!gst_bytestream_seek (dvdec->bs, position, GST_SEEK_METHOD_SET)) { |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 746 | res = FALSE; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 747 | } |
Wim Taymans | ada49e5 | 2003-05-24 10:34:34 +0000 | [diff] [blame] | 748 | if (GST_EVENT_TYPE (event) != GST_EVENT_SEEK_SEGMENT) |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 749 | dvdec->end_position = -1; |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 750 | break; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 751 | } |
| 752 | default: |
| 753 | res = FALSE; |
| 754 | break; |
| 755 | } |
Wim Taymans | eebc284 | 2002-07-08 19:31:05 +0000 | [diff] [blame] | 756 | gst_event_unref (event); |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 757 | return res; |
| 758 | } |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 759 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 760 | static GstCaps * |
| 761 | gst_dvdec_video_getcaps (GstPad * pad) |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 762 | { |
| 763 | GstDVDec *dvdec; |
| 764 | GstCaps *caps; |
| 765 | GstPadTemplate *src_pad_template; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 766 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 767 | dvdec = GST_DVDEC (gst_pad_get_parent (pad)); |
| 768 | src_pad_template = gst_static_pad_template_get (&video_src_temp); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 769 | caps = gst_caps_copy (gst_pad_template_get_caps (src_pad_template)); |
| 770 | |
| 771 | if (dvdec->found_header) { |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 772 | int i; |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 773 | gint par_x, par_y; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 774 | |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 775 | if (dvdec->PAL) { |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 776 | if (dvdec->wide) { |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 777 | par_x = PAL_WIDE_PAR_X; |
| 778 | par_y = PAL_WIDE_PAR_Y; |
| 779 | } else { |
| 780 | par_x = PAL_NORMAL_PAR_X; |
| 781 | par_y = PAL_NORMAL_PAR_Y; |
| 782 | } |
| 783 | } else { |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 784 | if (dvdec->wide) { |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 785 | par_x = NTSC_WIDE_PAR_X; |
| 786 | par_y = NTSC_WIDE_PAR_Y; |
| 787 | } else { |
| 788 | par_x = NTSC_NORMAL_PAR_X; |
| 789 | par_y = NTSC_NORMAL_PAR_Y; |
| 790 | } |
| 791 | } |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 792 | /* set the height */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 793 | for (i = 0; i < gst_caps_get_size (caps); i++) { |
| 794 | GstStructure *structure = gst_caps_get_structure (caps, i); |
| 795 | |
| 796 | gst_structure_set (structure, |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 797 | "height", G_TYPE_INT, dvdec->height, |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 798 | "framerate", G_TYPE_DOUBLE, dvdec->framerate / dvdec->drop_factor, |
Wim Taymans | b464238 | 2004-10-18 14:02:51 +0000 | [diff] [blame] | 799 | "pixel-aspect-ratio", GST_TYPE_FRACTION, par_x, par_y, NULL); |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 800 | } |
| 801 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 802 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 803 | return caps; |
| 804 | } |
| 805 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 806 | static GstPadLinkReturn |
| 807 | gst_dvdec_video_link (GstPad * pad, const GstCaps * caps) |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 808 | { |
| 809 | GstDVDec *dvdec; |
| 810 | GstStructure *structure; |
| 811 | guint32 fourcc; |
| 812 | gint height; |
| 813 | gdouble framerate; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 814 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 815 | dvdec = GST_DVDEC (gst_pad_get_parent (pad)); |
| 816 | |
| 817 | /* if we did not find a header yet, return delayed */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 818 | if (!dvdec->found_header) { |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 819 | return GST_PAD_LINK_DELAYED; |
| 820 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 821 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 822 | structure = gst_caps_get_structure (caps, 0); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 823 | |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 824 | if (!gst_structure_get_int (structure, "height", &height) || |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 825 | !gst_structure_get_double (structure, "framerate", &framerate)) |
| 826 | return GST_PAD_LINK_REFUSED; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 827 | |
Wim Taymans | 17d464c | 2004-10-26 17:59:18 +0000 | [diff] [blame^] | 828 | /* allow a margin of error for the framerate caused by float rounding errors */ |
| 829 | if ((height != dvdec->height) || |
| 830 | (fabs (framerate - (dvdec->framerate / dvdec->drop_factor)) > 0.00000001)) |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 831 | return GST_PAD_LINK_REFUSED; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 832 | |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 833 | if (strcmp (gst_structure_get_name (structure), "video/x-raw-rgb") == 0) { |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 834 | gint bpp; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 835 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 836 | gst_structure_get_int (structure, "bpp", &bpp); |
| 837 | if (bpp == 24) { |
| 838 | dvdec->space = e_dv_color_rgb; |
| 839 | dvdec->bpp = 3; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 840 | } else { |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 841 | dvdec->space = e_dv_color_bgr0; |
| 842 | dvdec->bpp = 4; |
| 843 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 844 | } else { |
Jan Schmidt | e9d7608 | 2004-05-07 16:17:25 +0000 | [diff] [blame] | 845 | if (!gst_structure_get_fourcc (structure, "format", &fourcc)) |
| 846 | return GST_PAD_LINK_REFUSED; |
| 847 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 848 | dvdec->space = e_dv_color_yuv; |
| 849 | dvdec->bpp = 2; |
| 850 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 851 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 852 | return GST_PAD_LINK_OK; |
| 853 | } |
| 854 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 855 | static void |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 856 | gst_dvdec_push (GstDVDec * dvdec, GstBuffer * outbuf, GstPad * pad, |
| 857 | GstClockTime ts) |
| 858 | { |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 859 | if ((dvdec->need_discont) || (dvdec->new_media)) { |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 860 | GstEvent *discont; |
| 861 | |
| 862 | discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, ts, NULL); |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 863 | GST_EVENT_DISCONT_NEW_MEDIA (discont) = dvdec->new_media; |
| 864 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 865 | gst_pad_push (pad, GST_DATA (discont)); |
| 866 | } |
| 867 | |
| 868 | gst_pad_push (pad, GST_DATA (outbuf)); |
| 869 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 870 | if ((dvdec->end_position != -1) && (dvdec->next_ts >= dvdec->end_position)) { |
| 871 | if (dvdec->loop) |
| 872 | gst_pad_push (pad, GST_DATA (gst_event_new (GST_EVENT_SEGMENT_DONE))); |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 873 | else |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 874 | gst_pad_push (pad, GST_DATA (gst_event_new (GST_EVENT_EOS))); |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 875 | } |
Jan Schmidt | 7ed5a3d | 2004-02-05 13:16:22 +0000 | [diff] [blame] | 876 | } |
| 877 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 878 | static void |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 879 | gst_dvdec_loop (GstElement * element) |
| 880 | { |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 881 | GstDVDec *dvdec; |
| 882 | GstBuffer *buf, *outbuf; |
| 883 | guint8 *inframe; |
| 884 | gint height; |
| 885 | guint32 length, got_bytes; |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 886 | GstClockTime ts, duration; |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 887 | gdouble fps; |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 888 | gboolean wide; |
Jan Schmidt | 7ed5a3d | 2004-02-05 13:16:22 +0000 | [diff] [blame] | 889 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 890 | dvdec = GST_DVDEC (element); |
| 891 | |
Jan Schmidt | e0006ee | 2004-04-01 11:48:27 +0000 | [diff] [blame] | 892 | /* |
| 893 | * Apparently dv_parse_header can read from the body of the frame |
| 894 | * too, so it needs more than header_size bytes. Wacky! |
| 895 | */ |
| 896 | if (dvdec->found_header) |
| 897 | length = (dvdec->PAL ? PAL_BUFFER : NTSC_BUFFER); |
| 898 | else |
| 899 | length = NTSC_BUFFER; |
| 900 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 901 | /* first read enough bytes to parse the header */ |
Jan Schmidt | e0006ee | 2004-04-01 11:48:27 +0000 | [diff] [blame] | 902 | got_bytes = gst_bytestream_peek_bytes (dvdec->bs, &inframe, length); |
| 903 | if (got_bytes < length) { |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 904 | gst_dvdec_handle_sink_event (dvdec); |
| 905 | return; |
| 906 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 907 | if (dv_parse_header (dvdec->decoder, inframe) < 0) { |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 908 | GST_ELEMENT_ERROR (dvdec, STREAM, DECODE, (NULL), (NULL)); |
| 909 | return; |
| 910 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 911 | |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 912 | /* after parsing the header we know the length of the data */ |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 913 | dvdec->PAL = dv_system_50_fields (dvdec->decoder); |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 914 | dvdec->found_header = TRUE; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 915 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 916 | fps = (dvdec->PAL ? PAL_FRAMERATE : NTSC_FRAMERATE); |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 917 | height = (dvdec->PAL ? PAL_HEIGHT : NTSC_HEIGHT); |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 918 | length = (dvdec->PAL ? PAL_BUFFER : NTSC_BUFFER); |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 919 | wide = dv_format_wide (dvdec->decoder); |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 920 | |
David Schleef | c0ada86 | 2004-02-05 23:15:00 +0000 | [diff] [blame] | 921 | if (length != dvdec->length) { |
| 922 | dvdec->length = length; |
| 923 | gst_bytestream_size_hint (dvdec->bs, length); |
| 924 | } |
| 925 | |
| 926 | /* then read the read data */ |
| 927 | got_bytes = gst_bytestream_read (dvdec->bs, &buf, length); |
| 928 | if (got_bytes < length) { |
| 929 | gst_dvdec_handle_sink_event (dvdec); |
| 930 | return; |
| 931 | } |
| 932 | |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 933 | ts = dvdec->next_ts; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 934 | dvdec->next_ts += GST_SECOND / fps; |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 935 | duration = dvdec->next_ts - ts; |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 936 | |
| 937 | dv_parse_packs (dvdec->decoder, GST_BUFFER_DATA (buf)); |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 938 | if (dv_is_new_recording (dvdec->decoder, GST_BUFFER_DATA (buf))) |
| 939 | dvdec->new_media = TRUE; |
Thomas Vander Stichele | be876ae | 2003-01-10 10:22:25 +0000 | [diff] [blame] | 940 | if (GST_PAD_IS_LINKED (dvdec->audiosrcpad)) { |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 941 | gint num_samples; |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 942 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 943 | dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 944 | dvdec->audio_buffers); |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 945 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 946 | if ((dv_get_frequency (dvdec->decoder) != dvdec->frequency) || |
| 947 | (dv_get_num_channels (dvdec->decoder) != dvdec->channels)) { |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 948 | if (!gst_pad_set_explicit_caps (dvdec->audiosrcpad, |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 949 | gst_caps_new_simple ("audio/x-raw-int", |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 950 | "rate", G_TYPE_INT, dv_get_frequency (dvdec->decoder), |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 951 | "depth", G_TYPE_INT, 16, |
| 952 | "width", G_TYPE_INT, 16, |
| 953 | "signed", G_TYPE_BOOLEAN, TRUE, |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 954 | "channels", G_TYPE_INT, dv_get_num_channels (dvdec->decoder), |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 955 | "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, NULL))) { |
| 956 | gst_buffer_unref (buf); |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 957 | GST_ELEMENT_ERROR (dvdec, CORE, NEGOTIATION, (NULL), |
| 958 | ("Failed to negotiate audio parameters for the DV audio stream")); |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 959 | return; |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 960 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 961 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 962 | dvdec->frequency = dv_get_frequency (dvdec->decoder); |
| 963 | dvdec->channels = dv_get_num_channels (dvdec->decoder); |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 964 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 965 | |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 966 | num_samples = dv_get_num_samples (dvdec->decoder); |
| 967 | |
| 968 | if (num_samples) { |
| 969 | gint16 *a_ptr; |
| 970 | gint i, j; |
| 971 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 972 | outbuf = gst_buffer_new (); |
| 973 | GST_BUFFER_SIZE (outbuf) = dv_get_num_samples (dvdec->decoder) * |
| 974 | sizeof (gint16) * dv_get_num_channels (dvdec->decoder); |
| 975 | GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf)); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 976 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 977 | a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 978 | |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 979 | for (i = 0; i < num_samples; i++) { |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 980 | for (j = 0; j < dv_get_num_channels (dvdec->decoder); j++) { |
| 981 | *(a_ptr++) = dvdec->audio_buffers[j][i]; |
| 982 | } |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 983 | } |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 984 | |
| 985 | GST_BUFFER_TIMESTAMP (outbuf) = ts; |
| 986 | GST_BUFFER_DURATION (outbuf) = duration; |
| 987 | GST_BUFFER_OFFSET (outbuf) = dvdec->audio_offset; |
| 988 | dvdec->audio_offset += num_samples; |
| 989 | GST_BUFFER_OFFSET_END (outbuf) = dvdec->audio_offset; |
| 990 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 991 | gst_dvdec_push (dvdec, outbuf, dvdec->audiosrcpad, ts); |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 992 | } |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 993 | } else { |
| 994 | dvdec->frequency = dv_get_frequency (dvdec->decoder); |
| 995 | dvdec->channels = dv_get_num_channels (dvdec->decoder); |
Wim Taymans | cdb004a | 2001-12-23 23:00:59 +0000 | [diff] [blame] | 996 | } |
Wim Taymans | ce3fd0b | 2002-06-13 22:30:15 +0000 | [diff] [blame] | 997 | |
Thomas Vander Stichele | be876ae | 2003-01-10 10:22:25 +0000 | [diff] [blame] | 998 | if (GST_PAD_IS_LINKED (dvdec->videosrcpad)) { |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 999 | guint8 *outframe; |
| 1000 | guint8 *outframe_ptrs[3]; |
| 1001 | gint outframe_pitches[3]; |
| 1002 | |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 1003 | dvdec->framecount++; |
| 1004 | if (dvdec->framecount < dvdec->drop_factor) { |
| 1005 | /* don't decode */ |
| 1006 | goto end; |
| 1007 | } |
| 1008 | dvdec->framecount = 0; |
| 1009 | |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 1010 | if ((dvdec->framerate != fps) || (dvdec->height != height) |
| 1011 | || dvdec->wide != wide) { |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 1012 | dvdec->height = height; |
| 1013 | dvdec->framerate = fps; |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 1014 | dvdec->wide = wide; |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 1015 | |
| 1016 | if (GST_PAD_LINK_FAILED (gst_pad_renegotiate (dvdec->videosrcpad))) { |
| 1017 | GST_ELEMENT_ERROR (dvdec, CORE, NEGOTIATION, (NULL), (NULL)); |
| 1018 | return; |
| 1019 | } |
| 1020 | } |
| 1021 | |
David Schleef | ce51f61 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 1022 | outbuf = gst_buffer_new_and_alloc ((720 * height) * dvdec->bpp); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1023 | |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 1024 | outframe = GST_BUFFER_DATA (outbuf); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1025 | |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 1026 | outframe_ptrs[0] = outframe; |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 1027 | outframe_pitches[0] = 720 * dvdec->bpp; |
Wim Taymans | b60d031 | 2002-06-16 20:49:22 +0000 | [diff] [blame] | 1028 | |
| 1029 | /* the rest only matters for YUY2 */ |
| 1030 | if (dvdec->bpp < 3) { |
| 1031 | outframe_ptrs[1] = outframe_ptrs[0] + 720 * height; |
| 1032 | outframe_ptrs[2] = outframe_ptrs[1] + 360 * height; |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1033 | |
Wim Taymans | b60d031 | 2002-06-16 20:49:22 +0000 | [diff] [blame] | 1034 | outframe_pitches[1] = height / 2; |
| 1035 | outframe_pitches[2] = outframe_pitches[1]; |
| 1036 | } |
Wim Taymans | cdb004a | 2001-12-23 23:00:59 +0000 | [diff] [blame] | 1037 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1038 | dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf), |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 1039 | dvdec->space, outframe_ptrs, outframe_pitches); |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 1040 | |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 1041 | GST_BUFFER_TIMESTAMP (outbuf) = ts; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 1042 | GST_BUFFER_DURATION (outbuf) = duration * dvdec->drop_factor; |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 1043 | |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 1044 | gst_dvdec_push (dvdec, outbuf, dvdec->videosrcpad, ts); |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 1045 | } else { |
| 1046 | dvdec->height = height; |
| 1047 | dvdec->framerate = fps; |
Wim Taymans | cda34e6 | 2004-10-18 17:49:09 +0000 | [diff] [blame] | 1048 | dvdec->wide = wide; |
Wim Taymans | 7f38fbb | 2002-06-15 14:32:35 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 1051 | end: |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1052 | if ((dvdec->end_position != -1) && |
| 1053 | (dvdec->next_ts >= dvdec->end_position) && !dvdec->loop) { |
Wim Taymans | 140d279 | 2002-11-02 13:34:42 +0000 | [diff] [blame] | 1054 | gst_element_set_eos (GST_ELEMENT (dvdec)); |
| 1055 | } |
Wim Taymans | db81699 | 2002-06-16 14:45:46 +0000 | [diff] [blame] | 1056 | |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 1057 | dvdec->need_discont = FALSE; |
| 1058 | dvdec->new_media = FALSE; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1059 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1060 | gst_buffer_unref (buf); |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static GstElementStateReturn |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1064 | gst_dvdec_change_state (GstElement * element) |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1065 | { |
| 1066 | GstDVDec *dvdec = GST_DVDEC (element); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1067 | |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1068 | switch (GST_STATE_TRANSITION (element)) { |
| 1069 | case GST_STATE_NULL_TO_READY: |
| 1070 | break; |
| 1071 | case GST_STATE_READY_TO_PAUSED: |
| 1072 | dvdec->bs = gst_bytestream_new (dvdec->sinkpad); |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1073 | dvdec->decoder = |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 1074 | dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma); |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 1075 | dvdec->decoder->quality = qualities[dvdec->quality]; |
Wim Taymans | 916be7a | 2004-06-27 14:42:09 +0000 | [diff] [blame] | 1076 | dvdec->audio_offset = 0; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 1077 | dvdec->framecount = 0; |
Jan Schmidt | e0006ee | 2004-04-01 11:48:27 +0000 | [diff] [blame] | 1078 | /* |
| 1079 | * Enable this function call when libdv2 0.100 or higher is more |
| 1080 | * common |
| 1081 | */ |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 1082 | /* dv_set_quality (dvdec->decoder, qualities [dvdec->quality]); */ |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1083 | break; |
| 1084 | case GST_STATE_PAUSED_TO_PLAYING: |
| 1085 | break; |
| 1086 | case GST_STATE_PLAYING_TO_PAUSED: |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1087 | break; |
| 1088 | case GST_STATE_PAUSED_TO_READY: |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 1089 | dv_decoder_free (dvdec->decoder); |
| 1090 | dvdec->decoder = NULL; |
Jan Schmidt | dd989ba | 2004-02-07 13:04:09 +0000 | [diff] [blame] | 1091 | dvdec->found_header = FALSE; |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1092 | gst_bytestream_destroy (dvdec->bs); |
Jan Schmidt | 192579e | 2004-06-07 12:01:52 +0000 | [diff] [blame] | 1093 | dvdec->bs = NULL; |
Wim Taymans | 36b7f1a | 2002-01-26 02:48:47 +0000 | [diff] [blame] | 1094 | break; |
| 1095 | case GST_STATE_READY_TO_NULL: |
| 1096 | break; |
| 1097 | default: |
| 1098 | break; |
| 1099 | } |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1100 | |
Jan Schmidt | 8542a1f | 2004-05-10 12:19:02 +0000 | [diff] [blame] | 1101 | return parent_class->change_state (element); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1104 | /* Arguments are part of the Gtk+ object system, and these functions |
| 1105 | * enable the element to respond to various arguments. |
| 1106 | */ |
| 1107 | static void |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1108 | gst_dvdec_set_property (GObject * object, guint prop_id, const GValue * value, |
| 1109 | GParamSpec * pspec) |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1110 | { |
| 1111 | GstDVDec *dvdec; |
| 1112 | |
| 1113 | /* It's not null if we got it, but it might not be ours */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1114 | g_return_if_fail (GST_IS_DVDEC (object)); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1115 | |
| 1116 | /* Get a pointer of the right type. */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1117 | dvdec = GST_DVDEC (object); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1118 | |
| 1119 | /* Check the argument id to see which argument we're setting. */ |
| 1120 | switch (prop_id) { |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 1121 | case ARG_CLAMP_LUMA: |
| 1122 | dvdec->clamp_luma = g_value_get_boolean (value); |
| 1123 | break; |
| 1124 | case ARG_CLAMP_CHROMA: |
| 1125 | dvdec->clamp_chroma = g_value_get_boolean (value); |
| 1126 | break; |
| 1127 | case ARG_QUALITY: |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 1128 | dvdec->quality = g_value_get_enum (value); |
| 1129 | if ((dvdec->quality < 0) || (dvdec->quality > 5)) |
| 1130 | dvdec->quality = 0; |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 1131 | break; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 1132 | case ARG_DECODE_NTH: |
| 1133 | dvdec->drop_factor = g_value_get_int (value); |
| 1134 | break; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1135 | default: |
Wim Taymans | 689fa8a | 2002-09-12 20:55:10 +0000 | [diff] [blame] | 1136 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | /* The set function is simply the inverse of the get fuction. */ |
| 1142 | static void |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1143 | gst_dvdec_get_property (GObject * object, guint prop_id, GValue * value, |
| 1144 | GParamSpec * pspec) |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1145 | { |
| 1146 | GstDVDec *dvdec; |
| 1147 | |
| 1148 | /* It's not null if we got it, but it might not be ours */ |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1149 | g_return_if_fail (GST_IS_DVDEC (object)); |
| 1150 | dvdec = GST_DVDEC (object); |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1151 | |
| 1152 | switch (prop_id) { |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 1153 | case ARG_CLAMP_LUMA: |
| 1154 | g_value_set_boolean (value, dvdec->clamp_luma); |
| 1155 | break; |
| 1156 | case ARG_CLAMP_CHROMA: |
| 1157 | g_value_set_boolean (value, dvdec->clamp_chroma); |
| 1158 | break; |
| 1159 | case ARG_QUALITY: |
Jan Schmidt | ea235cb | 2004-05-12 14:53:57 +0000 | [diff] [blame] | 1160 | g_value_set_enum (value, dvdec->quality); |
Wim Taymans | 4eaa7cc | 2002-09-09 22:20:34 +0000 | [diff] [blame] | 1161 | break; |
Wim Taymans | e5bb1f1 | 2004-06-27 16:38:41 +0000 | [diff] [blame] | 1162 | case ARG_DECODE_NTH: |
| 1163 | g_value_set_int (value, dvdec->drop_factor); |
| 1164 | break; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1165 | default: |
| 1166 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 1167 | break; |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | /* This is the entry into the plugin itself. When the plugin loads, |
| 1172 | * this function is called to register everything that the plugin provides. |
| 1173 | */ |
| 1174 | static gboolean |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1175 | plugin_init (GstPlugin * plugin) |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1176 | { |
Benjamin Otte | c9ae463 | 2003-10-28 20:52:41 +0000 | [diff] [blame] | 1177 | if (!gst_library_load ("gstbytestream")) |
| 1178 | return FALSE; |
| 1179 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1180 | if (!gst_element_register (plugin, "dvdec", GST_RANK_PRIMARY, |
Thomas Vander Stichele | 6cc1c73 | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 1181 | gst_dvdec_get_type ())) |
Jan Schmidt | c4ec05b | 2003-11-02 03:32:31 +0000 | [diff] [blame] | 1182 | return FALSE; |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1183 | |
Thomas Vander Stichele | b0f5f9a | 2001-12-23 16:42:33 +0000 | [diff] [blame] | 1184 | return TRUE; |
| 1185 | } |
| 1186 | |
Thomas Vander Stichele | 24aa823 | 2004-03-14 20:54:13 +0000 | [diff] [blame] | 1187 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, |
| 1188 | GST_VERSION_MINOR, |
| 1189 | "dvdec", |
| 1190 | "Uses libdv to decode DV video (libdv.sourceforge.net)", |
| 1191 | plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN); |