1.1 --- a/gst-gmyth/nuvdemux/gstnuvdemux.c Thu May 31 16:02:53 2007 +0100
1.2 +++ b/gst-gmyth/nuvdemux/gstnuvdemux.c Thu Jun 14 18:22:32 2007 +0100
1.3 @@ -58,112 +58,112 @@
1.4
1.5 #define GST_NUV_DEMUX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_NUV_DEMUX, GstNuvDemuxPrivate))
1.6
1.7 -GST_DEBUG_CATEGORY_STATIC (nuvdemux_debug);
1.8 +GST_DEBUG_CATEGORY_STATIC(nuvdemux_debug);
1.9 #define GST_CAT_DEFAULT nuvdemux_debug
1.10 #define GST_FLOW_ERROR_NO_DATA -101
1.11 #define GST_FLOW_ERROR_EOS -102
1.12
1.13 enum
1.14 {
1.15 - NUV_PUSH_MODE = 0,
1.16 - NUV_PULL_MODE
1.17 + NUV_PUSH_MODE = 0,
1.18 + NUV_PULL_MODE
1.19 };
1.20
1.21 -GST_DEBUG_CATEGORY_EXTERN (GST_CAT_EVENT);
1.22 +GST_DEBUG_CATEGORY_EXTERN(GST_CAT_EVENT);
1.23
1.24 static const GstElementDetails gst_nuv_demux_details =
1.25 -GST_ELEMENT_DETAILS ("Nuv demuxer",
1.26 - "Codec/Demuxer",
1.27 - "Demultiplex a .nuv file into audio and video",
1.28 - "Renato Araujo Oliveira Filho <renato.filho@indt.org.br>,"
1.29 - "Rosfran Borges <rosfran.borges@indt.org.br>");
1.30 +GST_ELEMENT_DETAILS("Nuv demuxer",
1.31 + "Codec/Demuxer",
1.32 + "Demultiplex a .nuv file into audio and video",
1.33 + "Renato Araujo Oliveira Filho <renato.filho@indt.org.br>,"
1.34 + "Rosfran Borges <rosfran.borges@indt.org.br>");
1.35
1.36
1.37 /* file header */
1.38 typedef struct
1.39 {
1.40 - gchar id[12]; /* "NuppelVideo\0" or "MythTVVideo\0" */
1.41 - gchar version[5]; /* "x.xx\0" */
1.42 + gchar id[12]; /* "NuppelVideo\0" or "MythTVVideo\0" */
1.43 + gchar version[5]; /* "x.xx\0" */
1.44
1.45 - gint i_width;
1.46 - gint i_height;
1.47 - gint i_width_desired;
1.48 - gint i_height_desired;
1.49 + gint i_width;
1.50 + gint i_height;
1.51 + gint i_width_desired;
1.52 + gint i_height_desired;
1.53
1.54 - gchar i_mode; /* P progressive, I interlaced */
1.55 + gchar i_mode; /* P progressive, I interlaced */
1.56
1.57 - gdouble d_aspect; /* 1.0 squared pixel */
1.58 - gdouble d_fps;
1.59 - //fps num/denom
1.60 - gint i_fpsn;
1.61 - gint i_fpsd;
1.62 + gdouble d_aspect; /* 1.0 squared pixel */
1.63 + gdouble d_fps;
1.64 + //fps num/denom
1.65 + gint i_fpsn;
1.66 + gint i_fpsd;
1.67
1.68 - gint i_video_blocks; /* 0 no video, -1 unknown */
1.69 - gint i_audio_blocks;
1.70 - gint i_text_blocks;
1.71 + gint i_video_blocks; /* 0 no video, -1 unknown */
1.72 + gint i_audio_blocks;
1.73 + gint i_text_blocks;
1.74
1.75 - gint i_keyframe_distance;
1.76 + gint i_keyframe_distance;
1.77
1.78 } nuv_header;
1.79
1.80 /* frame header */
1.81 typedef struct
1.82 {
1.83 - gchar i_type; /* A: audio, V: video, S: sync; T: test
1.84 - R: Seekpoint (string:RTjjjjjjjj)
1.85 - D: Extra data for codec */
1.86 - gchar i_compression; /* V: 0 uncompressed
1.87 - 1 RTJpeg
1.88 - 2 RTJpeg+lzo
1.89 - N black frame
1.90 - L copy last
1.91 - A: 0 uncompressed (44100 1-bits, 2ch)
1.92 - 1 lzo
1.93 - 2 layer 2
1.94 - 3 layer 3
1.95 - F flac
1.96 - S shorten
1.97 - N null frame loudless
1.98 - L copy last
1.99 - S: B audio and vdeo sync point
1.100 - A audio sync info (timecode == effective
1.101 - dsp frequency*100)
1.102 - V next video sync (timecode == next video
1.103 - frame num)
1.104 - S audio,video,text correlation */
1.105 - gchar i_keyframe; /* 0 keyframe, else no no key frame */
1.106 - guint8 i_filters; /* 0x01: gauss 5 pixel (8,2,2,2,2)/16
1.107 - 0x02: gauss 5 pixel (8,1,1,1,1)/12
1.108 - 0x04: cartoon filter */
1.109 + gchar i_type; /* A: audio, V: video, S: sync; T: test
1.110 + R: Seekpoint (string:RTjjjjjjjj)
1.111 + D: Extra data for codec */
1.112 + gchar i_compression; /* V: 0 uncompressed
1.113 + 1 RTJpeg
1.114 + 2 RTJpeg+lzo
1.115 + N black frame
1.116 + L copy last
1.117 + A: 0 uncompressed (44100 1-bits, 2ch)
1.118 + 1 lzo
1.119 + 2 layer 2
1.120 + 3 layer 3
1.121 + F flac
1.122 + S shorten
1.123 + N null frame loudless
1.124 + L copy last
1.125 + S: B audio and vdeo sync point
1.126 + A audio sync info (timecode == effective
1.127 + dsp frequency*100)
1.128 + V next video sync (timecode == next video
1.129 + frame num)
1.130 + S audio,video,text correlation */
1.131 + gchar i_keyframe; /* 0 keyframe, else no no key frame */
1.132 + guint8 i_filters; /* 0x01: gauss 5 pixel (8,2,2,2,2)/16
1.133 + 0x02: gauss 5 pixel (8,1,1,1,1)/12
1.134 + 0x04: cartoon filter */
1.135
1.136 - gint32 i_timecode; /* ms */
1.137 + gint32 i_timecode; /* ms */
1.138
1.139 - gint i_length; /* V,A,T: length of following data
1.140 - S: length of packet correl */
1.141 + gint i_length; /* V,A,T: length of following data
1.142 + S: length of packet correl */
1.143 } nuv_frame_header;
1.144
1.145
1.146 /* FIXME Not sure of this one */
1.147 typedef struct
1.148 {
1.149 - gint i_version;
1.150 - guint32 i_video_fcc;
1.151 + gint i_version;
1.152 + guint32 i_video_fcc;
1.153
1.154 - guint32 i_audio_fcc;
1.155 - gint i_audio_sample_rate;
1.156 - gint i_audio_bits_per_sample;
1.157 - gint i_audio_channels;
1.158 - gint i_audio_compression_ratio;
1.159 - gint i_audio_quality;
1.160 - gint i_rtjpeg_quality;
1.161 - gint i_rtjpeg_luma_filter;
1.162 - gint i_rtjpeg_chroma_filter;
1.163 - gint i_lavc_bitrate;
1.164 - gint i_lavc_qmin;
1.165 - gint i_lavc_qmax;
1.166 - gint i_lavc_maxqdiff;
1.167 - gint64 i_seekable_offset;
1.168 - gint64 i_keyframe_adjust_offset;
1.169 + guint32 i_audio_fcc;
1.170 + gint i_audio_sample_rate;
1.171 + gint i_audio_bits_per_sample;
1.172 + gint i_audio_channels;
1.173 + gint i_audio_compression_ratio;
1.174 + gint i_audio_quality;
1.175 + gint i_rtjpeg_quality;
1.176 + gint i_rtjpeg_luma_filter;
1.177 + gint i_rtjpeg_chroma_filter;
1.178 + gint i_lavc_bitrate;
1.179 + gint i_lavc_qmin;
1.180 + gint i_lavc_qmax;
1.181 + gint i_lavc_maxqdiff;
1.182 + gint64 i_seekable_offset;
1.183 + gint64 i_keyframe_adjust_offset;
1.184
1.185 } nuv_extended_header;
1.186
1.187 @@ -174,7 +174,8 @@
1.188
1.189 } frame_index_data;
1.190
1.191 -typedef enum {
1.192 +typedef enum
1.193 +{
1.194 GST_NUV_DEMUX_START,
1.195 GST_NUV_DEMUX_HEADER_DATA,
1.196 GST_NUV_DEMUX_EXTRA_DATA,
1.197 @@ -187,125 +188,132 @@
1.198 GST_NUV_DEMUX_INVALID_DATA
1.199 } GstNuvDemuxState;
1.200
1.201 -struct _GstNuvDemuxPrivate {
1.202 - /* used for indicate the mode */
1.203 - guint mode;
1.204 +struct _GstNuvDemuxPrivate
1.205 +{
1.206 + /* used for indicate the mode */
1.207 + guint mode;
1.208
1.209 - /* used on push mode */
1.210 - GstAdapter *adapter;
1.211 + /* used on push mode */
1.212 + GstAdapter *adapter;
1.213
1.214 - /* pads */
1.215 - GstPad *sinkpad;
1.216 - GstPad *src_video_pad;
1.217 - GstPad *src_audio_pad;
1.218 + /* pads */
1.219 + GstPad *sinkpad;
1.220 + GstPad *src_video_pad;
1.221 + GstPad *src_audio_pad;
1.222
1.223 - /* Flow control */
1.224 - GstFlowReturn last_video_return;
1.225 - GstFlowReturn last_audio_return;
1.226 - gboolean more_data;
1.227 - gboolean eos;
1.228 - gboolean new_file;
1.229 - guint segment;
1.230 + /* Flow control */
1.231 + GstFlowReturn last_video_return;
1.232 + GstFlowReturn last_audio_return;
1.233 + gboolean more_data;
1.234 + gboolean eos;
1.235 + gboolean new_file;
1.236 + guint segment;
1.237
1.238 - /* NUV decoding state */
1.239 - GstNuvDemuxState state;
1.240 - guint64 offset;
1.241 + /* NUV decoding state */
1.242 + GstNuvDemuxState state;
1.243 + guint64 offset;
1.244
1.245 - /* duration information */
1.246 - guint64 duration_bytes;
1.247 - guint64 duration_time;
1.248 - guint64 segment_stop;
1.249 - guint64 segment_start;
1.250 + /* duration information */
1.251 + guint64 duration_bytes;
1.252 + guint64 duration_time;
1.253 + guint64 segment_stop;
1.254 + guint64 segment_start;
1.255
1.256 - /* segment control info */
1.257 - gboolean new_audio_segment;
1.258 - gboolean new_video_segment;
1.259 + /* segment control info */
1.260 + gboolean new_audio_segment;
1.261 + gboolean new_video_segment;
1.262
1.263 - /* Mpeg ExtraData */
1.264 - guint64 mpeg_data_size;
1.265 - GstBuffer *mpeg_buffer;
1.266 + /* Mpeg ExtraData */
1.267 + guint64 mpeg_data_size;
1.268 + GstBuffer *mpeg_buffer;
1.269
1.270 - /* Headers */
1.271 + /* Headers */
1.272 nuv_header h;
1.273 nuv_extended_header eh;
1.274 nuv_frame_header fh;
1.275
1.276 - /* anothers info */
1.277 - guint64 header_lengh;
1.278 - gint64 time_start;
1.279 - gint64 time_diff;
1.280 - gint64 time_qos;
1.281 - guint64 last_frame_time;
1.282 - GSList *index;
1.283 + /* anothers info */
1.284 + guint64 header_lengh;
1.285 + gint64 time_start;
1.286 + gint64 time_diff;
1.287 + gint64 time_qos;
1.288 + guint64 last_frame_time;
1.289 + GSList *index;
1.290 };
1.291
1.292
1.293 -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
1.294 - GST_PAD_SINK,
1.295 - GST_PAD_ALWAYS,
1.296 - GST_STATIC_CAPS ("video/x-nuv"));
1.297 +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE("sink",
1.298 + GST_PAD_SINK,
1.299 + GST_PAD_ALWAYS,
1.300 + GST_STATIC_CAPS
1.301 + ("video/x-nuv"));
1.302
1.303 static GstStaticPadTemplate audio_src_template =
1.304 -GST_STATIC_PAD_TEMPLATE ("audio_src",
1.305 - GST_PAD_SRC,
1.306 - GST_PAD_SOMETIMES,
1.307 - GST_STATIC_CAPS_ANY);
1.308 +GST_STATIC_PAD_TEMPLATE("audio_src",
1.309 + GST_PAD_SRC,
1.310 + GST_PAD_SOMETIMES,
1.311 + GST_STATIC_CAPS_ANY);
1.312
1.313 static GstStaticPadTemplate video_src_template =
1.314 -GST_STATIC_PAD_TEMPLATE ("video_src",
1.315 - GST_PAD_SRC,
1.316 - GST_PAD_SOMETIMES,
1.317 - GST_STATIC_CAPS_ANY);
1.318 +GST_STATIC_PAD_TEMPLATE("video_src",
1.319 + GST_PAD_SRC,
1.320 + GST_PAD_SOMETIMES,
1.321 + GST_STATIC_CAPS_ANY);
1.322
1.323 -static void gst_nuv_demux_dispose (GObject * object);
1.324 -static void gst_nuv_demux_finalize (GObject * object);
1.325 -static GstStateChangeReturn gst_nuv_demux_change_state (GstElement * element,
1.326 - GstStateChange transition);
1.327 -static void gst_nuv_demux_loop (GstPad * pad);
1.328 -static GstFlowReturn gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf);
1.329 -static GstFlowReturn gst_nuv_demux_play (GstPad * pad);
1.330 -static gboolean gst_nuv_demux_sink_activate_pull (GstPad * sinkpad,
1.331 - gboolean active);
1.332 -static gboolean gst_nuv_demux_sink_activate_push (GstPad * pad,
1.333 - gboolean active);
1.334 -static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad);
1.335 -static gboolean gst_nuv_demux_sink_event (GstPad *pad, GstEvent *event);
1.336 -static gboolean gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event);
1.337 -static frame_index_data * gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos,
1.338 - gint64 segment_stop, GstFormat format);
1.339 +static void gst_nuv_demux_dispose(GObject * object);
1.340 +static void gst_nuv_demux_finalize(GObject * object);
1.341 +static GstStateChangeReturn gst_nuv_demux_change_state(GstElement * element,
1.342 + GstStateChange
1.343 + transition);
1.344 +static void gst_nuv_demux_loop(GstPad * pad);
1.345 +static GstFlowReturn gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf);
1.346 +static GstFlowReturn gst_nuv_demux_play(GstPad * pad);
1.347 +static gboolean gst_nuv_demux_sink_activate_pull(GstPad * sinkpad,
1.348 + gboolean active);
1.349 +static gboolean gst_nuv_demux_sink_activate_push(GstPad * pad,
1.350 + gboolean active);
1.351 +static gboolean gst_nuv_demux_sink_activate(GstPad * sinkpad);
1.352 +static gboolean gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event);
1.353 +static gboolean gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event);
1.354 +static frame_index_data *gst_nuv_demux_do_seek_index(GstNuvDemux * nuv,
1.355 + gint64 seek_pos,
1.356 + gint64 segment_stop,
1.357 + GstFormat format);
1.358
1.359
1.360 -static GstFlowReturn gst_nuv_demux_move_bytes (GstNuvDemux * nuv, guint64 size);
1.361 -static GstFlowReturn gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size,
1.362 - gboolean move, GstBuffer ** buffer);
1.363 -static void gst_nuv_demux_reset (GstNuvDemux * nuv);
1.364 -static void gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv);
1.365 -static void gst_nuv_demux_send_eos (GstNuvDemux * nuv);
1.366 -static void gst_nuv_demux_create_seek_index (GstNuvDemux * nuv);
1.367 +static GstFlowReturn gst_nuv_demux_move_bytes(GstNuvDemux * nuv,
1.368 + guint64 size);
1.369 +static GstFlowReturn gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size,
1.370 + gboolean move,
1.371 + GstBuffer ** buffer);
1.372 +static void gst_nuv_demux_reset(GstNuvDemux * nuv);
1.373 +static void gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv);
1.374 +static void gst_nuv_demux_send_eos(GstNuvDemux * nuv);
1.375 +static void gst_nuv_demux_create_seek_index(GstNuvDemux * nuv);
1.376
1.377
1.378 -#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1.379 -GstBuffer * gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes);
1.380 +#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1.381 +GstBuffer *gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes);
1.382 #endif
1.383
1.384
1.385 -GST_BOILERPLATE (GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
1.386 +GST_BOILERPLATE(GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
1.387
1.388 /******************************************************************************
1.389 * Utils function
1.390 ******************************************************************************/
1.391 #if G_BYTE_ORDER == G_BIG_ENDIAN
1.392 static inline gdouble
1.393 -_gdouble_swap_le_be (gdouble * d)
1.394 +_gdouble_swap_le_be(gdouble * d)
1.395 {
1.396 union
1.397 {
1.398 - guint64 i;
1.399 - gdouble d;
1.400 + guint64 i;
1.401 + gdouble d;
1.402 } u;
1.403
1.404 u.d = *d;
1.405 - u.i = GUINT64_SWAP_LE_BE (u.i);
1.406 + u.i = GUINT64_SWAP_LE_BE(u.i);
1.407 return u.d;
1.408 }
1.409
1.410 @@ -315,169 +323,186 @@
1.411 #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */
1.412
1.413 static void
1.414 -double2fraction (double in, int *num, int *denom)
1.415 +double2fraction(double in, int *num, int *denom)
1.416 {
1.417 - if (in == 29.97) {
1.418 - *num = 30000;
1.419 - *denom = 1001;
1.420 - } else if (in == 23.976) {
1.421 - *num = 24000;
1.422 - *denom = 1001;
1.423 - } else {
1.424 - *denom = 1;
1.425 - while (in - floor(in) >= 0.1) {
1.426 - *denom *= 10;
1.427 - in *= 10.0;
1.428 - }
1.429 - *num = (int)floor(in);
1.430 - }
1.431 + if (in == 29.97)
1.432 + {
1.433 + *num = 30000;
1.434 + *denom = 1001;
1.435 + }
1.436 + else if (in == 23.976)
1.437 + {
1.438 + *num = 24000;
1.439 + *denom = 1001;
1.440 + }
1.441 + else
1.442 + {
1.443 + *denom = 1;
1.444 + while (in - floor(in) >= 0.1)
1.445 + {
1.446 + *denom *= 10;
1.447 + in *= 10.0;
1.448 + }
1.449 + *num = (int) floor(in);
1.450 + }
1.451 }
1.452
1.453 /* GObject Functions */
1.454
1.455 static void
1.456 -gst_nuv_demux_base_init (gpointer klass)
1.457 +gst_nuv_demux_base_init(gpointer klass)
1.458 {
1.459 - GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
1.460 + GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
1.461
1.462 - gst_element_class_add_pad_template (element_class,
1.463 - gst_static_pad_template_get (&audio_src_template));
1.464 + gst_element_class_add_pad_template(element_class,
1.465 + gst_static_pad_template_get
1.466 + (&audio_src_template));
1.467
1.468 - gst_element_class_add_pad_template (element_class,
1.469 - gst_static_pad_template_get (&video_src_template));
1.470 + gst_element_class_add_pad_template(element_class,
1.471 + gst_static_pad_template_get
1.472 + (&video_src_template));
1.473
1.474 - gst_element_class_add_pad_template (element_class,
1.475 - gst_static_pad_template_get (&sink_template));
1.476 - gst_element_class_set_details (element_class, &gst_nuv_demux_details);
1.477 + gst_element_class_add_pad_template(element_class,
1.478 + gst_static_pad_template_get
1.479 + (&sink_template));
1.480 + gst_element_class_set_details(element_class, &gst_nuv_demux_details);
1.481 }
1.482
1.483 static void
1.484 -gst_nuv_demux_class_init (GstNuvDemuxClass * klass)
1.485 +gst_nuv_demux_class_init(GstNuvDemuxClass * klass)
1.486 {
1.487 - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
1.488 + GstElementClass *gstelement_class = GST_ELEMENT_CLASS(klass);
1.489 GObjectClass *gobject_class = (GObjectClass *) klass;
1.490
1.491 - GST_DEBUG_CATEGORY_INIT (nuvdemux_debug, "nuvdemux",
1.492 - 0, "Demuxer for NUV streams");
1.493 + GST_DEBUG_CATEGORY_INIT(nuvdemux_debug, "nuvdemux",
1.494 + 0, "Demuxer for NUV streams");
1.495
1.496 - parent_class = g_type_class_peek_parent (klass);
1.497 + parent_class = g_type_class_peek_parent(klass);
1.498
1.499 gobject_class->dispose = gst_nuv_demux_dispose;
1.500 gobject_class->finalize = gst_nuv_demux_finalize;
1.501 gstelement_class->change_state = gst_nuv_demux_change_state;
1.502
1.503 - g_type_class_add_private (gobject_class, sizeof (GstNuvDemuxPrivate));
1.504 + g_type_class_add_private(gobject_class, sizeof(GstNuvDemuxPrivate));
1.505 }
1.506
1.507 static void
1.508 -gst_nuv_demux_init (GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
1.509 +gst_nuv_demux_init(GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
1.510 {
1.511 - nuv->priv = GST_NUV_DEMUX_GET_PRIVATE (nuv);
1.512 - nuv->priv->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
1.513 + nuv->priv = GST_NUV_DEMUX_GET_PRIVATE(nuv);
1.514 + nuv->priv->sinkpad =
1.515 + gst_pad_new_from_static_template(&sink_template, "sink");
1.516
1.517 - /* creating adapter */
1.518 + /* creating adapter */
1.519 nuv->priv->mode = NUV_PUSH_MODE;
1.520 - nuv->priv->adapter = gst_adapter_new ();
1.521 + nuv->priv->adapter = gst_adapter_new();
1.522
1.523 nuv->priv->new_audio_segment = TRUE;
1.524 nuv->priv->new_video_segment = TRUE;
1.525
1.526 - gst_pad_set_activate_function (nuv->priv->sinkpad, gst_nuv_demux_sink_activate);
1.527 - gst_pad_set_activatepull_function (nuv->priv->sinkpad,
1.528 - gst_nuv_demux_sink_activate_pull);
1.529 - gst_pad_set_activatepush_function (nuv->priv->sinkpad,
1.530 - gst_nuv_demux_sink_activate_push);
1.531 - gst_pad_set_chain_function (nuv->priv->sinkpad,
1.532 - GST_DEBUG_FUNCPTR (gst_nuv_demux_chain));
1.533 - gst_pad_set_event_function (nuv->priv->sinkpad,
1.534 - GST_DEBUG_FUNCPTR (gst_nuv_demux_sink_event));
1.535 + gst_pad_set_activate_function(nuv->priv->sinkpad,
1.536 + gst_nuv_demux_sink_activate);
1.537 + gst_pad_set_activatepull_function(nuv->priv->sinkpad,
1.538 + gst_nuv_demux_sink_activate_pull);
1.539 + gst_pad_set_activatepush_function(nuv->priv->sinkpad,
1.540 + gst_nuv_demux_sink_activate_push);
1.541 + gst_pad_set_chain_function(nuv->priv->sinkpad,
1.542 + GST_DEBUG_FUNCPTR(gst_nuv_demux_chain));
1.543 + gst_pad_set_event_function(nuv->priv->sinkpad,
1.544 + GST_DEBUG_FUNCPTR(gst_nuv_demux_sink_event));
1.545
1.546
1.547 - gst_element_add_pad (GST_ELEMENT (nuv), nuv->priv->sinkpad);
1.548 + gst_element_add_pad(GST_ELEMENT(nuv), nuv->priv->sinkpad);
1.549
1.550 }
1.551
1.552 static void
1.553 -gst_nuv_demux_dispose (GObject * object)
1.554 +gst_nuv_demux_dispose(GObject * object)
1.555 {
1.556 - GstNuvDemux *nuv = GST_NUV_DEMUX (object);
1.557 + GstNuvDemux *nuv = GST_NUV_DEMUX(object);
1.558
1.559
1.560 - if (nuv->priv->mpeg_buffer != NULL) {
1.561 - gst_buffer_unref (nuv->priv->mpeg_buffer);
1.562 - }
1.563 + if (nuv->priv->mpeg_buffer != NULL)
1.564 + {
1.565 + gst_buffer_unref(nuv->priv->mpeg_buffer);
1.566 + }
1.567
1.568 - gst_nuv_demux_reset (GST_NUV_DEMUX (object));
1.569 - gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (object));
1.570 + gst_nuv_demux_reset(GST_NUV_DEMUX(object));
1.571 + gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(object));
1.572
1.573 - if (nuv->priv->adapter != NULL) {
1.574 - gst_object_unref (nuv->priv->adapter);
1.575 - }
1.576 + if (nuv->priv->adapter != NULL)
1.577 + {
1.578 + gst_object_unref(nuv->priv->adapter);
1.579 + }
1.580 }
1.581
1.582 static void
1.583 -gst_nuv_demux_finalize (GObject * object)
1.584 +gst_nuv_demux_finalize(GObject * object)
1.585 {
1.586 - G_OBJECT_CLASS (parent_class)->finalize (object);
1.587 + G_OBJECT_CLASS(parent_class)->finalize(object);
1.588 }
1.589
1.590
1.591 /* HeaderLoad:
1.592 */
1.593 static GstFlowReturn
1.594 -gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header *h)
1.595 +gst_nuv_demux_header_load(GstNuvDemux * nuv, nuv_header * h)
1.596 {
1.597 GstBuffer *buffer = NULL;
1.598 - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer);
1.599 + GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 72, TRUE, &buffer);
1.600
1.601 - if ((res != GST_FLOW_OK) || (buffer == NULL)) {
1.602 - goto done;
1.603 - }
1.604 + if ((res != GST_FLOW_OK) || (buffer == NULL))
1.605 + {
1.606 + goto done;
1.607 + }
1.608
1.609 - if (h != NULL) {
1.610 - memcpy (h->id, buffer->data, 12);
1.611 - memcpy (h->version, buffer->data + 12, 5);
1.612 - h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
1.613 - h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
1.614 - h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
1.615 - h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
1.616 - h->i_mode = GPOINTER_TO_INT (buffer->data[36]);
1.617 - h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
1.618 - h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
1.619 - /* get the num and denom values from fps */
1.620 - double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd);
1.621 - h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
1.622 - h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
1.623 - h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
1.624 - h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
1.625 + if (h != NULL)
1.626 + {
1.627 + memcpy(h->id, buffer->data, 12);
1.628 + memcpy(h->version, buffer->data + 12, 5);
1.629 + h->i_width = GST_READ_UINT32_LE(&buffer->data[20]);
1.630 + h->i_height = GST_READ_UINT32_LE(&buffer->data[24]);
1.631 + h->i_width_desired = GST_READ_UINT32_LE(&buffer->data[28]);
1.632 + h->i_height_desired = GST_READ_UINT32_LE(&buffer->data[32]);
1.633 + h->i_mode = GPOINTER_TO_INT(buffer->data[36]);
1.634 + h->d_aspect = READ_DOUBLE_FROM_LE(&buffer->data[40]);
1.635 + h->d_fps = READ_DOUBLE_FROM_LE(&buffer->data[48]);
1.636 + /* get the num and denom values from fps */
1.637 + double2fraction(h->d_fps, &h->i_fpsn, &h->i_fpsd);
1.638 + h->i_video_blocks = GST_READ_UINT32_LE(&buffer->data[56]);
1.639 + h->i_audio_blocks = GST_READ_UINT32_LE(&buffer->data[60]);
1.640 + h->i_text_blocks = GST_READ_UINT32_LE(&buffer->data[64]);
1.641 + h->i_keyframe_distance = GST_READ_UINT32_LE(&buffer->data[68]);
1.642
1.643 - GST_DEBUG_OBJECT (nuv,
1.644 - "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
1.645 - h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
1.646 - h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
1.647 - h->i_keyframe_distance);
1.648 - }
1.649 + GST_DEBUG_OBJECT(nuv,
1.650 + "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d",
1.651 + h->id, h->version, h->i_width, h->i_height,
1.652 + h->d_aspect, h->d_fps, h->i_video_blocks,
1.653 + h->i_audio_blocks, h->i_text_blocks,
1.654 + h->i_keyframe_distance);
1.655 + }
1.656
1.657 done:
1.658 - if (buffer != NULL) {
1.659 - gst_buffer_unref (buffer);
1.660 - buffer = NULL;
1.661 - }
1.662 + if (buffer != NULL)
1.663 + {
1.664 + gst_buffer_unref(buffer);
1.665 + buffer = NULL;
1.666 + }
1.667 return res;
1.668 }
1.669
1.670 static GstFlowReturn
1.671 -gst_nuv_demux_stream_header_data (GstNuvDemux * nuv)
1.672 +gst_nuv_demux_stream_header_data(GstNuvDemux * nuv)
1.673 {
1.674 GstFlowReturn res;
1.675
1.676 - if (nuv->priv->new_file)
1.677 - res = gst_nuv_demux_header_load (nuv, NULL);
1.678 + if (nuv->priv->new_file)
1.679 + res = gst_nuv_demux_header_load(nuv, NULL);
1.680 else
1.681 - res = gst_nuv_demux_header_load (nuv, &nuv->priv->h);
1.682 + res = gst_nuv_demux_header_load(nuv, &nuv->priv->h);
1.683
1.684 if (res == GST_FLOW_OK)
1.685 - nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
1.686 + nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
1.687 return res;
1.688 }
1.689
1.690 @@ -485,258 +510,286 @@
1.691 * Read NUV file tag
1.692 */
1.693 static GstFlowReturn
1.694 -gst_nuv_demux_stream_file_header (GstNuvDemux * nuv)
1.695 +gst_nuv_demux_stream_file_header(GstNuvDemux * nuv)
1.696 {
1.697 GstFlowReturn res = GST_FLOW_OK;
1.698 GstBuffer *file_header = NULL;
1.699
1.700 - res = gst_nuv_demux_read_bytes (nuv, 12, FALSE, &file_header);
1.701 - if (res == GST_FLOW_OK) {
1.702 - if (strncmp ((gchar *) file_header->data, "MythTVVideo", 11) ||
1.703 - strncmp ((gchar *) file_header->data, "NuppelVideo", 11)) {
1.704 - nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
1.705 - } else {
1.706 - GST_DEBUG_OBJECT (nuv, "error parsing file header");
1.707 - nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1.708 - res = GST_FLOW_ERROR;
1.709 - }
1.710 - }
1.711 + res = gst_nuv_demux_read_bytes(nuv, 12, FALSE, &file_header);
1.712 + if (res == GST_FLOW_OK)
1.713 + {
1.714 + if (strncmp((gchar *) file_header->data, "MythTVVideo", 11) ||
1.715 + strncmp((gchar *) file_header->data, "NuppelVideo", 11))
1.716 + {
1.717 + nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
1.718 + }
1.719 + else
1.720 + {
1.721 + GST_DEBUG_OBJECT(nuv, "error parsing file header");
1.722 + nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1.723 + res = GST_FLOW_ERROR;
1.724 + }
1.725 + }
1.726
1.727 - if (file_header != NULL) {
1.728 - gst_buffer_unref (file_header);
1.729 - file_header = NULL;
1.730 - }
1.731 + if (file_header != NULL)
1.732 + {
1.733 + gst_buffer_unref(file_header);
1.734 + file_header = NULL;
1.735 + }
1.736 return res;
1.737 }
1.738
1.739 /* FrameHeaderLoad:
1.740 */
1.741 static GstFlowReturn
1.742 -gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header *h)
1.743 +gst_nuv_demux_frame_header_load(GstNuvDemux * nuv, nuv_frame_header * h)
1.744 {
1.745 unsigned char *data;
1.746 GstBuffer *buf = NULL;
1.747
1.748 - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf);
1.749 + GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 12, TRUE, &buf);
1.750
1.751 - if ((res != GST_FLOW_OK) || (buf == NULL)) {
1.752 - goto done;
1.753 - }
1.754 + if ((res != GST_FLOW_OK) || (buf == NULL))
1.755 + {
1.756 + goto done;
1.757 + }
1.758
1.759 if (h == NULL)
1.760 goto done;
1.761 -
1.762 +
1.763 data = buf->data;
1.764
1.765 - h->i_type = GPOINTER_TO_INT (data[0]);
1.766 - h->i_compression = GPOINTER_TO_INT (data[1]);
1.767 - h->i_keyframe = GPOINTER_TO_INT (data[2]);
1.768 - h->i_filters = GPOINTER_TO_INT (data[3]);
1.769 - h->i_timecode = GST_READ_UINT32_LE (&data[4]);
1.770 - h->i_length = GST_READ_UINT32_LE (&data[8]);
1.771 + h->i_type = GPOINTER_TO_INT(data[0]);
1.772 + h->i_compression = GPOINTER_TO_INT(data[1]);
1.773 + h->i_keyframe = GPOINTER_TO_INT(data[2]);
1.774 + h->i_filters = GPOINTER_TO_INT(data[3]);
1.775 + h->i_timecode = GST_READ_UINT32_LE(&data[4]);
1.776 + h->i_length = GST_READ_UINT32_LE(&data[8]);
1.777
1.778 - GST_DEBUG_OBJECT (nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
1.779 - h->i_type,
1.780 - h->i_compression ? h->i_compression : ' ',
1.781 - h->i_keyframe ? h->i_keyframe : ' ',
1.782 - h->i_filters, h->i_timecode, h->i_length);
1.783 + GST_DEBUG_OBJECT(nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
1.784 + h->i_type,
1.785 + h->i_compression ? h->i_compression : ' ',
1.786 + h->i_keyframe ? h->i_keyframe : ' ',
1.787 + h->i_filters, h->i_timecode, h->i_length);
1.788
1.789 -done:
1.790 - if (buf != NULL) {
1.791 - gst_buffer_unref (buf);
1.792 - buf = NULL;
1.793 - }
1.794 +done:
1.795 + if (buf != NULL)
1.796 + {
1.797 + gst_buffer_unref(buf);
1.798 + buf = NULL;
1.799 + }
1.800
1.801 return res;
1.802 }
1.803
1.804 static GstFlowReturn
1.805 -gst_nuv_demux_extended_header_load (GstNuvDemux * nuv,
1.806 - nuv_extended_header * h)
1.807 +gst_nuv_demux_extended_header_load(GstNuvDemux * nuv, nuv_extended_header * h)
1.808 {
1.809 unsigned char *data;
1.810 GstBuffer *buff = NULL;
1.811
1.812 - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff);
1.813 + GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 512, TRUE, &buff);
1.814
1.815 - if ((res != GST_FLOW_OK) || (buff == NULL)) {
1.816 - goto done;
1.817 - }
1.818 + if ((res != GST_FLOW_OK) || (buff == NULL))
1.819 + {
1.820 + goto done;
1.821 + }
1.822
1.823 if (h == NULL)
1.824 - goto done;
1.825 + goto done;
1.826
1.827 data = buff->data;
1.828 - h->i_version = GST_READ_UINT32_LE (&data[0]);
1.829 - h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
1.830 - h->i_audio_fcc = GST_MAKE_FOURCC (data[8], data[9], data[10], data[11]);
1.831 - h->i_audio_sample_rate = GST_READ_UINT32_LE (&data[12]);
1.832 - h->i_audio_bits_per_sample = GST_READ_UINT32_LE (&data[16]);
1.833 - h->i_audio_channels = GST_READ_UINT32_LE (&data[20]);
1.834 - h->i_audio_compression_ratio = GST_READ_UINT32_LE (&data[24]);
1.835 - h->i_audio_quality = GST_READ_UINT32_LE (&data[28]);
1.836 - h->i_rtjpeg_quality = GST_READ_UINT32_LE (&data[32]);
1.837 - h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE (&data[36]);
1.838 - h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE (&data[40]);
1.839 - h->i_lavc_bitrate = GST_READ_UINT32_LE (&data[44]);
1.840 - h->i_lavc_qmin = GST_READ_UINT32_LE (&data[48]);
1.841 - h->i_lavc_qmin = GST_READ_UINT32_LE (&data[52]);
1.842 - h->i_lavc_maxqdiff = GST_READ_UINT32_LE (&data[56]);
1.843 - h->i_seekable_offset = GST_READ_UINT64_LE (&data[60]);
1.844 - h->i_keyframe_adjust_offset = GST_READ_UINT64_LE (&data[68]);
1.845 + h->i_version = GST_READ_UINT32_LE(&data[0]);
1.846 + h->i_video_fcc = GST_MAKE_FOURCC(data[4], data[5], data[6], data[7]);
1.847 + h->i_audio_fcc = GST_MAKE_FOURCC(data[8], data[9], data[10], data[11]);
1.848 + h->i_audio_sample_rate = GST_READ_UINT32_LE(&data[12]);
1.849 + h->i_audio_bits_per_sample = GST_READ_UINT32_LE(&data[16]);
1.850 + h->i_audio_channels = GST_READ_UINT32_LE(&data[20]);
1.851 + h->i_audio_compression_ratio = GST_READ_UINT32_LE(&data[24]);
1.852 + h->i_audio_quality = GST_READ_UINT32_LE(&data[28]);
1.853 + h->i_rtjpeg_quality = GST_READ_UINT32_LE(&data[32]);
1.854 + h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE(&data[36]);
1.855 + h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE(&data[40]);
1.856 + h->i_lavc_bitrate = GST_READ_UINT32_LE(&data[44]);
1.857 + h->i_lavc_qmin = GST_READ_UINT32_LE(&data[48]);
1.858 + h->i_lavc_qmin = GST_READ_UINT32_LE(&data[52]);
1.859 + h->i_lavc_maxqdiff = GST_READ_UINT32_LE(&data[56]);
1.860 + h->i_seekable_offset = GST_READ_UINT64_LE(&data[60]);
1.861 + h->i_keyframe_adjust_offset = GST_READ_UINT64_LE(&data[68]);
1.862
1.863 - GST_DEBUG_OBJECT (nuv,
1.864 - "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
1.865 - "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
1.866 - h->i_version, (gchar *) & h->i_video_fcc, (gchar *) & h->i_audio_fcc,
1.867 - h->i_audio_sample_rate, h->i_audio_bits_per_sample, h->i_audio_channels,
1.868 - h->i_audio_compression_ratio, h->i_audio_quality, h->i_rtjpeg_quality,
1.869 - h->i_rtjpeg_luma_filter, h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
1.870 - h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset,
1.871 - h->i_keyframe_adjust_offset);
1.872 + GST_DEBUG_OBJECT(nuv,
1.873 + "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
1.874 + "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
1.875 + h->i_version, (gchar *) & h->i_video_fcc,
1.876 + (gchar *) & h->i_audio_fcc, h->i_audio_sample_rate,
1.877 + h->i_audio_bits_per_sample, h->i_audio_channels,
1.878 + h->i_audio_compression_ratio, h->i_audio_quality,
1.879 + h->i_rtjpeg_quality, h->i_rtjpeg_luma_filter,
1.880 + h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
1.881 + h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff,
1.882 + h->i_seekable_offset, h->i_keyframe_adjust_offset);
1.883
1.884 done:
1.885 - if (buff != NULL) {
1.886 - gst_buffer_unref (buff);
1.887 - buff = NULL;
1.888 - }
1.889 + if (buff != NULL)
1.890 + {
1.891 + gst_buffer_unref(buff);
1.892 + buff = NULL;
1.893 + }
1.894 return res;
1.895 }
1.896
1.897
1.898 /* Query Functions */
1.899 static const GstQueryType *
1.900 -gst_nuv_demux_get_src_query_types (GstPad * pad)
1.901 +gst_nuv_demux_get_src_query_types(GstPad * pad)
1.902 {
1.903 static const GstQueryType src_types[] = {
1.904 - GST_QUERY_POSITION,
1.905 - GST_QUERY_DURATION,
1.906 - 0
1.907 + GST_QUERY_POSITION,
1.908 + GST_QUERY_DURATION,
1.909 + 0
1.910 };
1.911
1.912 return src_types;
1.913 }
1.914
1.915 static gboolean
1.916 -gst_nuv_demux_handle_src_query (GstPad * pad, GstQuery * query)
1.917 +gst_nuv_demux_handle_src_query(GstPad * pad, GstQuery * query)
1.918 {
1.919 gboolean res = FALSE;
1.920 - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1.921 + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1.922
1.923
1.924 - switch (GST_QUERY_TYPE (query))
1.925 - {
1.926 - case GST_QUERY_POSITION:
1.927 + switch (GST_QUERY_TYPE(query))
1.928 {
1.929 + case GST_QUERY_POSITION:
1.930 + {
1.931 GstFormat format;
1.932 - gst_query_parse_position (query, &format, NULL);
1.933 - switch (format)
1.934 - {
1.935 - case GST_FORMAT_TIME:
1.936 - if (GST_CLOCK_TIME_IS_VALID (nuv->priv->last_frame_time)) {
1.937 - gst_query_set_position (query, GST_FORMAT_TIME, nuv->priv->last_frame_time);
1.938 - res = TRUE;
1.939 - }
1.940 - break;
1.941 - default:
1.942 - break;
1.943 - }
1.944 + gst_query_parse_position(query, &format, NULL);
1.945 + switch (format)
1.946 + {
1.947 + case GST_FORMAT_TIME:
1.948 + if (GST_CLOCK_TIME_IS_VALID(nuv->priv->last_frame_time))
1.949 + {
1.950 + gst_query_set_position(query, GST_FORMAT_TIME,
1.951 + nuv->priv->last_frame_time);
1.952 + res = TRUE;
1.953 + }
1.954 + break;
1.955 + default:
1.956 + break;
1.957 + }
1.958 break;
1.959 - }
1.960 - case GST_QUERY_DURATION:
1.961 - {
1.962 - GstFormat format;
1.963 - gst_query_parse_duration (query, &format, NULL);
1.964 - switch (format)
1.965 + }
1.966 + case GST_QUERY_DURATION:
1.967 {
1.968 - case GST_FORMAT_TIME:
1.969 - if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE) {
1.970 - gst_query_set_duration (query, GST_FORMAT_TIME, nuv->priv->duration_time);
1.971 - res = TRUE;
1.972 - }
1.973 - break;
1.974 - default:
1.975 - break;
1.976 + GstFormat format;
1.977 + gst_query_parse_duration(query, &format, NULL);
1.978 + switch (format)
1.979 + {
1.980 + case GST_FORMAT_TIME:
1.981 + if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE)
1.982 + {
1.983 + gst_query_set_duration(query, GST_FORMAT_TIME,
1.984 + nuv->priv->duration_time);
1.985 + res = TRUE;
1.986 + }
1.987 + break;
1.988 + default:
1.989 + break;
1.990 + }
1.991 + break;
1.992 }
1.993 - break;
1.994 - }
1.995 default:
1.996 break;
1.997 - }
1.998 + }
1.999
1.1000 - if (res==FALSE) {
1.1001 - res = gst_pad_query_default (pad, query);
1.1002 - }
1.1003 + if (res == FALSE)
1.1004 + {
1.1005 + res = gst_pad_query_default(pad, query);
1.1006 + }
1.1007
1.1008 - gst_object_unref (nuv);
1.1009 + gst_object_unref(nuv);
1.1010 return res;
1.1011 }
1.1012
1.1013 -static GstPad*
1.1014 -gst_nuv_demux_create_pad (GstNuvDemux *nuv, GstCaps *caps, GstStaticPadTemplate *template, const gchar* name)
1.1015 +static GstPad *
1.1016 +gst_nuv_demux_create_pad(GstNuvDemux * nuv, GstCaps * caps,
1.1017 + GstStaticPadTemplate * template, const gchar * name)
1.1018 {
1.1019 - GstPad *pad = NULL;
1.1020 - pad = gst_pad_new_from_static_template (template, name);
1.1021 - gst_pad_set_caps (pad, caps);
1.1022 - gst_pad_set_active (pad, TRUE);
1.1023 - gst_pad_use_fixed_caps (pad);
1.1024 - gst_element_add_pad (GST_ELEMENT (nuv), pad);
1.1025 + GstPad *pad = NULL;
1.1026 + pad = gst_pad_new_from_static_template(template, name);
1.1027 + gst_pad_set_caps(pad, caps);
1.1028 + gst_pad_set_active(pad, TRUE);
1.1029 + gst_pad_use_fixed_caps(pad);
1.1030 + gst_element_add_pad(GST_ELEMENT(nuv), pad);
1.1031
1.1032 - gst_pad_set_event_function (pad,
1.1033 - GST_DEBUG_FUNCPTR (gst_nuv_demux_srcpad_event));
1.1034 + gst_pad_set_event_function(pad,
1.1035 + GST_DEBUG_FUNCPTR(gst_nuv_demux_srcpad_event));
1.1036
1.1037 - gst_pad_set_query_type_function (pad,
1.1038 - GST_DEBUG_FUNCPTR (gst_nuv_demux_get_src_query_types));
1.1039 + gst_pad_set_query_type_function(pad,
1.1040 + GST_DEBUG_FUNCPTR
1.1041 + (gst_nuv_demux_get_src_query_types));
1.1042
1.1043 - gst_pad_set_query_function (pad,
1.1044 - GST_DEBUG_FUNCPTR (gst_nuv_demux_handle_src_query));
1.1045 -
1.1046 + gst_pad_set_query_function(pad,
1.1047 + GST_DEBUG_FUNCPTR
1.1048 + (gst_nuv_demux_handle_src_query));
1.1049
1.1050 - return pad;
1.1051 +
1.1052 + return pad;
1.1053 }
1.1054
1.1055 static void
1.1056 -gst_nuv_demux_create_pads (GstNuvDemux * nuv)
1.1057 +gst_nuv_demux_create_pads(GstNuvDemux * nuv)
1.1058 {
1.1059 - if (nuv->priv->h.i_video_blocks != 0) {
1.1060 - GstCaps *video_caps = NULL;
1.1061 + if (nuv->priv->h.i_video_blocks != 0)
1.1062 + {
1.1063 + GstCaps *video_caps = NULL;
1.1064
1.1065 - video_caps = gst_caps_new_simple ("video/x-divx",
1.1066 - "divxversion", G_TYPE_INT, 4,
1.1067 - "width", G_TYPE_INT, nuv->priv->h.i_width,
1.1068 - "height", G_TYPE_INT, nuv->priv->h.i_height,
1.1069 - "framerate", GST_TYPE_FRACTION, nuv->priv->h.i_fpsn, nuv->priv->h.i_fpsd,
1.1070 - "format", GST_TYPE_FOURCC, nuv->priv->eh.i_video_fcc,
1.1071 - "pixel-aspect-ratio", GST_TYPE_FRACTION,
1.1072 - (gint) (nuv->priv->h.d_aspect * 1000.0f), 1000, NULL);
1.1073 + video_caps = gst_caps_new_simple("video/x-divx",
1.1074 + "divxversion", G_TYPE_INT, 4,
1.1075 + "width", G_TYPE_INT,
1.1076 + nuv->priv->h.i_width, "height",
1.1077 + G_TYPE_INT, nuv->priv->h.i_height,
1.1078 + "framerate", GST_TYPE_FRACTION,
1.1079 + nuv->priv->h.i_fpsn,
1.1080 + nuv->priv->h.i_fpsd, "format",
1.1081 + GST_TYPE_FOURCC,
1.1082 + nuv->priv->eh.i_video_fcc,
1.1083 + "pixel-aspect-ratio",
1.1084 + GST_TYPE_FRACTION,
1.1085 + (gint) (nuv->priv->h.d_aspect *
1.1086 + 1000.0f), 1000, NULL);
1.1087
1.1088 - nuv->priv->src_video_pad = gst_nuv_demux_create_pad (nuv, video_caps, &video_src_template, "video_src");
1.1089 - gst_caps_unref (video_caps);
1.1090 - }
1.1091 + nuv->priv->src_video_pad =
1.1092 + gst_nuv_demux_create_pad(nuv, video_caps, &video_src_template,
1.1093 + "video_src");
1.1094 + gst_caps_unref(video_caps);
1.1095 + }
1.1096
1.1097 - if (nuv->priv->h.i_audio_blocks != 0) {
1.1098 - GstCaps *audio_caps = NULL;
1.1099 + if (nuv->priv->h.i_audio_blocks != 0)
1.1100 + {
1.1101 + GstCaps *audio_caps = NULL;
1.1102
1.1103 - audio_caps = gst_caps_new_simple ("audio/mpeg",
1.1104 - "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate,
1.1105 - "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc,
1.1106 - "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels,
1.1107 - "layer", G_TYPE_INT, 3, // fixme: magic number
1.1108 - "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version, NULL);
1.1109 -
1.1110 - nuv->priv->src_audio_pad = gst_nuv_demux_create_pad (nuv, audio_caps, &audio_src_template, "audio_src");
1.1111 - gst_caps_unref (audio_caps);
1.1112 - }
1.1113 + audio_caps = gst_caps_new_simple("audio/mpeg", "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate, "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc, "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels, "layer", G_TYPE_INT, 3, // fixme: magic number
1.1114 + "mpegversion", G_TYPE_INT,
1.1115 + nuv->priv->eh.i_version, NULL);
1.1116
1.1117 - gst_element_no_more_pads (GST_ELEMENT (nuv));
1.1118 + nuv->priv->src_audio_pad =
1.1119 + gst_nuv_demux_create_pad(nuv, audio_caps, &audio_src_template,
1.1120 + "audio_src");
1.1121 + gst_caps_unref(audio_caps);
1.1122 + }
1.1123 +
1.1124 + gst_element_no_more_pads(GST_ELEMENT(nuv));
1.1125 }
1.1126
1.1127 static gboolean
1.1128 -gst_nuv_demux_validate_header (nuv_frame_header *h)
1.1129 +gst_nuv_demux_validate_header(nuv_frame_header * h)
1.1130 {
1.1131 gboolean valid = FALSE;
1.1132 - //g_usleep (1 * G_USEC_PER_SEC );
1.1133 - switch (h->i_type) {
1.1134 + //g_usleep (1 * G_USEC_PER_SEC );
1.1135 + switch (h->i_type)
1.1136 + {
1.1137 /*
1.1138 case 'V':
1.1139 if (h->i_compression == 0 ||
1.1140 @@ -768,63 +821,65 @@
1.1141 }
1.1142 break;
1.1143 */
1.1144 - case 'A':
1.1145 - case 'V':
1.1146 - case 'S':
1.1147 - case 'R':
1.1148 - case 'D':
1.1149 - case 'Q':
1.1150 - valid = TRUE;
1.1151 - break;
1.1152 - default:
1.1153 - valid = FALSE;
1.1154 - }
1.1155 + case 'A':
1.1156 + case 'V':
1.1157 + case 'S':
1.1158 + case 'R':
1.1159 + case 'D':
1.1160 + case 'Q':
1.1161 + valid = TRUE;
1.1162 + break;
1.1163 + default:
1.1164 + valid = FALSE;
1.1165 + }
1.1166
1.1167 return valid;
1.1168 }
1.1169
1.1170 static GstFlowReturn
1.1171 -gst_nuv_demux_read_head_frame (GstNuvDemux * nuv)
1.1172 +gst_nuv_demux_read_head_frame(GstNuvDemux * nuv)
1.1173 {
1.1174 GstFlowReturn ret = GST_FLOW_OK;
1.1175 gboolean valid = FALSE;
1.1176
1.1177 - do {
1.1178 - ret = gst_nuv_demux_frame_header_load (nuv, &nuv->priv->fh);
1.1179 - if (ret != GST_FLOW_OK) {
1.1180 - return ret;
1.1181 - }
1.1182 + do
1.1183 + {
1.1184 + ret = gst_nuv_demux_frame_header_load(nuv, &nuv->priv->fh);
1.1185 + if (ret != GST_FLOW_OK)
1.1186 + {
1.1187 + return ret;
1.1188 + }
1.1189
1.1190 - if (gst_nuv_demux_validate_header (&nuv->priv->fh) == TRUE)
1.1191 - valid = TRUE;
1.1192 + if (gst_nuv_demux_validate_header(&nuv->priv->fh) == TRUE)
1.1193 + valid = TRUE;
1.1194
1.1195 - } while (valid == FALSE);
1.1196 + }
1.1197 + while (valid == FALSE);
1.1198
1.1199 nuv->priv->state = GST_NUV_DEMUX_MOVI;
1.1200 return ret;
1.1201 }
1.1202
1.1203 static gboolean
1.1204 -gst_nuv_combine_flow (GstNuvDemux *nuv)
1.1205 +gst_nuv_combine_flow(GstNuvDemux * nuv)
1.1206 {
1.1207 - GstFlowReturn ret_video = nuv->priv->last_video_return;
1.1208 - GstFlowReturn ret_audio = nuv->priv->last_audio_return;
1.1209 + GstFlowReturn ret_video = nuv->priv->last_video_return;
1.1210 + GstFlowReturn ret_audio = nuv->priv->last_audio_return;
1.1211
1.1212 - if ((ret_video != GST_FLOW_OK) &&
1.1213 - (ret_audio != GST_FLOW_OK))
1.1214 - return FALSE;
1.1215 + if ((ret_video != GST_FLOW_OK) && (ret_audio != GST_FLOW_OK))
1.1216 + return FALSE;
1.1217
1.1218 - if (GST_FLOW_IS_FATAL (ret_video))
1.1219 - return FALSE;
1.1220 + if (GST_FLOW_IS_FATAL(ret_video))
1.1221 + return FALSE;
1.1222
1.1223 - if (GST_FLOW_IS_FATAL (ret_audio))
1.1224 - return FALSE;
1.1225 + if (GST_FLOW_IS_FATAL(ret_audio))
1.1226 + return FALSE;
1.1227
1.1228 - return TRUE;
1.1229 + return TRUE;
1.1230 }
1.1231
1.1232 static GstFlowReturn
1.1233 -gst_nuv_demux_stream_data (GstNuvDemux * nuv)
1.1234 +gst_nuv_demux_stream_data(GstNuvDemux * nuv)
1.1235 {
1.1236 GstFlowReturn ret = GST_FLOW_OK;
1.1237 GstPad *pad = NULL;
1.1238 @@ -834,539 +889,653 @@
1.1239
1.1240 h = nuv->priv->fh;
1.1241
1.1242 - if (h.i_type == 'R') {
1.1243 - goto done;
1.1244 - }
1.1245 -
1.1246 - if (h.i_length > 0) {
1.1247 - ret = gst_nuv_demux_read_bytes (nuv, h.i_length, TRUE, &buf);
1.1248 - if ((ret != GST_FLOW_OK) || (buf == NULL)) {
1.1249 - goto done;
1.1250 - }
1.1251 -
1.1252 - if ((h.i_timecode < 0)) {
1.1253 - h.i_timecode = 0;
1.1254 - //goto done;
1.1255 - }
1.1256 -
1.1257 - timestamp = h.i_timecode * GST_MSECOND;
1.1258 - GST_BUFFER_TIMESTAMP (buf) = timestamp;
1.1259 - }
1.1260 - else {
1.1261 - goto done;
1.1262 - }
1.1263 -
1.1264 -
1.1265 - switch (h.i_type) {
1.1266 - case 'V':
1.1267 - {
1.1268 - pad = nuv->priv->src_video_pad;
1.1269 -
1.1270 - if (nuv->priv->new_video_segment) {
1.1271 -
1.1272 - /* send new segment event*/
1.1273 - gst_pad_push_event (nuv->priv->src_video_pad,
1.1274 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
1.1275 - GST_CLOCK_TIME_NONE, 0));
1.1276 -
1.1277 - if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
1.1278 - nuv->priv->time_start = timestamp;
1.1279 - }
1.1280 - nuv->priv->new_video_segment = FALSE;
1.1281 - }
1.1282 -
1.1283 - break;
1.1284 - }
1.1285 - case 'A':
1.1286 - {
1.1287 - pad = nuv->priv->src_audio_pad;
1.1288 -
1.1289 - if (nuv->priv->new_audio_segment) {
1.1290 - /* send new segment event*/
1.1291 - gst_pad_push_event (nuv->priv->src_audio_pad,
1.1292 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
1.1293 - GST_CLOCK_TIME_NONE, 0));
1.1294 -
1.1295 - if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
1.1296 - nuv->priv->time_start = timestamp;
1.1297 - }
1.1298 - nuv->priv->new_audio_segment = FALSE;
1.1299 - }
1.1300 -
1.1301 - break;
1.1302 - }
1.1303 - case 'S':
1.1304 - {
1.1305 - switch (h.i_compression) {
1.1306 - case 'V':
1.1307 - GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h.i_timecode);
1.1308 - gst_pad_push_event (nuv->priv->src_video_pad,
1.1309 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h.i_timecode * GST_MSECOND,
1.1310 - GST_CLOCK_TIME_NONE, 0));
1.1311 - break;
1.1312 - case 'A':
1.1313 - GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h.i_timecode);
1.1314 - gst_pad_push_event (nuv->priv->src_audio_pad,
1.1315 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
1.1316 - GST_CLOCK_TIME_NONE, 0));
1.1317 - break;
1.1318 - default:
1.1319 - break;
1.1320 - }
1.1321 - goto done;
1.1322 - }
1.1323 - default:
1.1324 - break;
1.1325 - }
1.1326 -
1.1327 - if ((buf != NULL) && (pad != NULL)) {
1.1328 - /* pushing the buffer */
1.1329 - gst_buffer_set_caps (buf, GST_PAD_CAPS (pad));
1.1330 - ret = gst_pad_push (pad, buf);
1.1331 - buf = NULL;
1.1332 -
1.1333 - if (ret != GST_FLOW_OK) {
1.1334 - GST_WARNING_OBJECT (nuv, "error: %d pushing on srcpad %s", ret, gst_pad_get_name (pad));
1.1335 -
1.1336 - if (pad == nuv->priv->src_video_pad) {
1.1337 - nuv->priv->last_video_return = ret;
1.1338 - }
1.1339 - else if (pad == nuv->priv->src_audio_pad) {
1.1340 - nuv->priv->last_audio_return = ret;
1.1341 - }
1.1342 -
1.1343 - /* verify anothers flow if is necessary stop task */
1.1344 - if (gst_nuv_combine_flow (nuv) != FALSE) {
1.1345 - ret = GST_FLOW_OK;
1.1346 - } else {
1.1347 - GST_WARNING_OBJECT (nuv, "error: on push");
1.1348 + if (h.i_type == 'R')
1.1349 + {
1.1350 + goto done;
1.1351 }
1.1352
1.1353 - }
1.1354 - }
1.1355 + if (h.i_length > 0)
1.1356 + {
1.1357 + ret = gst_nuv_demux_read_bytes(nuv, h.i_length, TRUE, &buf);
1.1358 + if ((ret != GST_FLOW_OK) || (buf == NULL))
1.1359 + {
1.1360 + goto done;
1.1361 + }
1.1362 +
1.1363 + if ((h.i_timecode < 0))
1.1364 + {
1.1365 + h.i_timecode = 0;
1.1366 + //goto done;
1.1367 + }
1.1368 +
1.1369 + timestamp = h.i_timecode * GST_MSECOND;
1.1370 + GST_BUFFER_TIMESTAMP(buf) = timestamp;
1.1371 + }
1.1372 + else
1.1373 + {
1.1374 + goto done;
1.1375 + }
1.1376 +
1.1377 +
1.1378 + switch (h.i_type)
1.1379 + {
1.1380 + case 'V':
1.1381 + {
1.1382 + pad = nuv->priv->src_video_pad;
1.1383 +
1.1384 + if (nuv->priv->new_video_segment)
1.1385 + {
1.1386 +
1.1387 + /* send new segment event */
1.1388 + gst_pad_push_event(nuv->priv->src_video_pad,
1.1389 + gst_event_new_new_segment(TRUE, 1.0,
1.1390 + GST_FORMAT_TIME, 0,
1.1391 + GST_CLOCK_TIME_NONE,
1.1392 + 0));
1.1393 +
1.1394 + if (nuv->priv->time_start == GST_CLOCK_TIME_NONE)
1.1395 + {
1.1396 + nuv->priv->time_start = timestamp;
1.1397 + }
1.1398 + nuv->priv->new_video_segment = FALSE;
1.1399 + }
1.1400 +
1.1401 + break;
1.1402 + }
1.1403 + case 'A':
1.1404 + {
1.1405 + pad = nuv->priv->src_audio_pad;
1.1406 +
1.1407 + if (nuv->priv->new_audio_segment)
1.1408 + {
1.1409 + /* send new segment event */
1.1410 + gst_pad_push_event(nuv->priv->src_audio_pad,
1.1411 + gst_event_new_new_segment(TRUE, 1.0,
1.1412 + GST_FORMAT_TIME, 0,
1.1413 + GST_CLOCK_TIME_NONE,
1.1414 + 0));
1.1415 +
1.1416 + if (nuv->priv->time_start == GST_CLOCK_TIME_NONE)
1.1417 + {
1.1418 + nuv->priv->time_start = timestamp;
1.1419 + }
1.1420 + nuv->priv->new_audio_segment = FALSE;
1.1421 + }
1.1422 +
1.1423 + break;
1.1424 + }
1.1425 + case 'S':
1.1426 + {
1.1427 + switch (h.i_compression)
1.1428 + {
1.1429 + case 'V':
1.1430 + GST_DEBUG_OBJECT(nuv, "sending new video segment: %d",
1.1431 + h.i_timecode);
1.1432 + gst_pad_push_event(nuv->priv->src_video_pad,
1.1433 + gst_event_new_new_segment(TRUE, 1.0,
1.1434 + GST_FORMAT_TIME,
1.1435 + h.i_timecode *
1.1436 + GST_MSECOND,
1.1437 + GST_CLOCK_TIME_NONE,
1.1438 + 0));
1.1439 + break;
1.1440 + case 'A':
1.1441 + GST_DEBUG_OBJECT(nuv, "sending new audio segment: %d",
1.1442 + h.i_timecode);
1.1443 + gst_pad_push_event(nuv->priv->src_audio_pad,
1.1444 + gst_event_new_new_segment(TRUE, 1.0,
1.1445 + GST_FORMAT_TIME, 0,
1.1446 + GST_CLOCK_TIME_NONE,
1.1447 + 0));
1.1448 + break;
1.1449 + default:
1.1450 + break;
1.1451 + }
1.1452 + goto done;
1.1453 + }
1.1454 + default:
1.1455 + break;
1.1456 + }
1.1457 +
1.1458 + if ((buf != NULL) && (pad != NULL))
1.1459 + {
1.1460 + /* pushing the buffer */
1.1461 + gst_buffer_set_caps(buf, GST_PAD_CAPS(pad));
1.1462 + ret = gst_pad_push(pad, buf);
1.1463 + buf = NULL;
1.1464 +
1.1465 + if (ret != GST_FLOW_OK)
1.1466 + {
1.1467 + GST_WARNING_OBJECT(nuv, "error: %d pushing on srcpad %s", ret,
1.1468 + gst_pad_get_name(pad));
1.1469 +
1.1470 + if (pad == nuv->priv->src_video_pad)
1.1471 + {
1.1472 + nuv->priv->last_video_return = ret;
1.1473 + }
1.1474 + else if (pad == nuv->priv->src_audio_pad)
1.1475 + {
1.1476 + nuv->priv->last_audio_return = ret;
1.1477 + }
1.1478 +
1.1479 + /* verify anothers flow if is necessary stop task */
1.1480 + if (gst_nuv_combine_flow(nuv) != FALSE)
1.1481 + {
1.1482 + ret = GST_FLOW_OK;
1.1483 + }
1.1484 + else
1.1485 + {
1.1486 + GST_WARNING_OBJECT(nuv, "error: on push");
1.1487 + }
1.1488 +
1.1489 + }
1.1490 + }
1.1491
1.1492 done:
1.1493 - if (buf != NULL) {
1.1494 - gst_buffer_unref (buf);
1.1495 - buf = NULL;
1.1496 - }
1.1497 - if (ret == GST_FLOW_OK) {
1.1498 - nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1.1499 - memset (&nuv->priv->fh, 0, sizeof (nuv->priv->fh));
1.1500 - }
1.1501 + if (buf != NULL)
1.1502 + {
1.1503 + gst_buffer_unref(buf);
1.1504 + buf = NULL;
1.1505 + }
1.1506 + if (ret == GST_FLOW_OK)
1.1507 + {
1.1508 + nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1.1509 + memset(&nuv->priv->fh, 0, sizeof(nuv->priv->fh));
1.1510 + }
1.1511 return ret;
1.1512 }
1.1513
1.1514 static GstFlowReturn
1.1515 -gst_nuv_demux_stream_mpeg_data (GstNuvDemux * nuv)
1.1516 +gst_nuv_demux_stream_mpeg_data(GstNuvDemux * nuv)
1.1517 {
1.1518 GstFlowReturn ret = GST_FLOW_OK;
1.1519
1.1520 - /* ffmpeg extra data */
1.1521 - if (nuv->priv->new_file) {
1.1522 - GstBuffer *buf;
1.1523 - ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, &buf);
1.1524 - gst_buffer_unref (buf);
1.1525 - } else {
1.1526 - ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE,
1.1527 - &nuv->priv->mpeg_buffer);
1.1528 - }
1.1529 + /* ffmpeg extra data */
1.1530 + if (nuv->priv->new_file)
1.1531 + {
1.1532 + GstBuffer *buf;
1.1533 + ret =
1.1534 + gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE, &buf);
1.1535 + gst_buffer_unref(buf);
1.1536 + }
1.1537 + else
1.1538 + {
1.1539 + ret = gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE,
1.1540 + &nuv->priv->mpeg_buffer);
1.1541 + }
1.1542
1.1543 - if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) {
1.1544 - return ret;
1.1545 - }
1.1546 + if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL))
1.1547 + {
1.1548 + return ret;
1.1549 + }
1.1550
1.1551 - GST_BUFFER_SIZE (nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size;
1.1552 + GST_BUFFER_SIZE(nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size;
1.1553 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1.1554 return ret;
1.1555 }
1.1556
1.1557 static GstFlowReturn
1.1558 -gst_nuv_demux_stream_extra_data (GstNuvDemux * nuv)
1.1559 +gst_nuv_demux_stream_extra_data(GstNuvDemux * nuv)
1.1560 {
1.1561 GstFlowReturn ret = GST_FLOW_OK;
1.1562
1.1563 - /* Load 'D' */
1.1564 + /* Load 'D' */
1.1565 nuv_frame_header h;
1.1566
1.1567 - if (nuv->priv->new_file)
1.1568 - ret = gst_nuv_demux_frame_header_load (nuv, NULL);
1.1569 - else
1.1570 - ret = gst_nuv_demux_frame_header_load (nuv, &h);
1.1571 + if (nuv->priv->new_file)
1.1572 + ret = gst_nuv_demux_frame_header_load(nuv, NULL);
1.1573 + else
1.1574 + ret = gst_nuv_demux_frame_header_load(nuv, &h);
1.1575
1.1576 if (ret != GST_FLOW_OK)
1.1577 - return ret;
1.1578 + return ret;
1.1579
1.1580 - if (h.i_type != 'D') {
1.1581 - GST_WARNING_OBJECT (nuv, "Unsuported rtjpeg");
1.1582 - return GST_FLOW_NOT_SUPPORTED;
1.1583 - }
1.1584 + if (h.i_type != 'D')
1.1585 + {
1.1586 + GST_WARNING_OBJECT(nuv, "Unsuported rtjpeg");
1.1587 + return GST_FLOW_NOT_SUPPORTED;
1.1588 + }
1.1589
1.1590 - if (h.i_length > 0) {
1.1591 - if (h.i_compression == 'F') {
1.1592 - nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
1.1593 - } else {
1.1594 - GST_WARNING_OBJECT (nuv, "only file with extended chunk are supported");
1.1595 - return GST_FLOW_NOT_SUPPORTED;
1.1596 - }
1.1597 - } else {
1.1598 - nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1.1599 - }
1.1600 + if (h.i_length > 0)
1.1601 + {
1.1602 + if (h.i_compression == 'F')
1.1603 + {
1.1604 + nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
1.1605 + }
1.1606 + else
1.1607 + {
1.1608 + GST_WARNING_OBJECT(nuv,
1.1609 + "only file with extended chunk are supported");
1.1610 + return GST_FLOW_NOT_SUPPORTED;
1.1611 + }
1.1612 + }
1.1613 + else
1.1614 + {
1.1615 + nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1.1616 + }
1.1617
1.1618 return ret;
1.1619 }
1.1620
1.1621 static GstFlowReturn
1.1622 -gst_nuv_demux_stream_extend_header_data (GstNuvDemux * nuv)
1.1623 +gst_nuv_demux_stream_extend_header_data(GstNuvDemux * nuv)
1.1624 {
1.1625 GstFlowReturn ret = GST_FLOW_OK;
1.1626
1.1627 if (nuv->priv->new_file)
1.1628 - ret = gst_nuv_demux_extended_header_load (nuv, NULL);
1.1629 - else {
1.1630 - ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh);
1.1631 + ret = gst_nuv_demux_extended_header_load(nuv, NULL);
1.1632 + else
1.1633 + {
1.1634 + ret = gst_nuv_demux_extended_header_load(nuv, &nuv->priv->eh);
1.1635 if (ret != GST_FLOW_OK)
1.1636 - return ret;
1.1637 - gst_nuv_demux_create_pads (nuv);
1.1638 - }
1.1639 + return ret;
1.1640 + gst_nuv_demux_create_pads(nuv);
1.1641 + }
1.1642
1.1643 nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE;
1.1644 return ret;
1.1645 }
1.1646
1.1647 static GstFlowReturn
1.1648 -gst_nuv_demux_stream_extend_header (GstNuvDemux * nuv)
1.1649 +gst_nuv_demux_stream_extend_header(GstNuvDemux * nuv)
1.1650 {
1.1651 GstBuffer *buf = NULL;
1.1652 GstFlowReturn res = GST_FLOW_OK;
1.1653
1.1654 - res = gst_nuv_demux_read_bytes (nuv, 1, FALSE, &buf);
1.1655 - if ((res != GST_FLOW_OK) || (buf == NULL)) {
1.1656 - if (buf != NULL) {
1.1657 - gst_buffer_unref (buf);
1.1658 - }
1.1659 - return res;
1.1660 - }
1.1661 + res = gst_nuv_demux_read_bytes(nuv, 1, FALSE, &buf);
1.1662 + if ((res != GST_FLOW_OK) || (buf == NULL))
1.1663 + {
1.1664 + if (buf != NULL)
1.1665 + {
1.1666 + gst_buffer_unref(buf);
1.1667 + }
1.1668 + return res;
1.1669 + }
1.1670
1.1671 - if (buf->data[0] == 'X') {
1.1672 - gst_buffer_unref (buf);
1.1673 - buf = NULL;
1.1674 - nuv_frame_header h;
1.1675 + if (buf->data[0] == 'X')
1.1676 + {
1.1677 + gst_buffer_unref(buf);
1.1678 + buf = NULL;
1.1679 + nuv_frame_header h;
1.1680
1.1681 - res = gst_nuv_demux_frame_header_load (nuv, &h);
1.1682 - if (res != GST_FLOW_OK)
1.1683 - return res;
1.1684 + res = gst_nuv_demux_frame_header_load(nuv, &h);
1.1685 + if (res != GST_FLOW_OK)
1.1686 + return res;
1.1687
1.1688 - if (h.i_length != 512) {
1.1689 - return GST_FLOW_ERROR;
1.1690 - }
1.1691 - nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1.1692 - } else {
1.1693 - nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1.1694 - g_object_unref (buf);
1.1695 - GST_ELEMENT_WARNING (nuv, STREAM, FAILED,
1.1696 - (_("incomplete NUV support")), ("incomplete NUV support"));
1.1697 - return GST_FLOW_ERROR;
1.1698 - }
1.1699 + if (h.i_length != 512)
1.1700 + {
1.1701 + return GST_FLOW_ERROR;
1.1702 + }
1.1703 + nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1.1704 + }
1.1705 + else
1.1706 + {
1.1707 + nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1.1708 + g_object_unref(buf);
1.1709 + GST_ELEMENT_WARNING(nuv, STREAM, FAILED,
1.1710 + (_("incomplete NUV support")),
1.1711 + ("incomplete NUV support"));
1.1712 + return GST_FLOW_ERROR;
1.1713 + }
1.1714 return res;
1.1715 }
1.1716
1.1717 static void
1.1718 -gst_nuv_demux_create_seek_index (GstNuvDemux * nuv)
1.1719 +gst_nuv_demux_create_seek_index(GstNuvDemux * nuv)
1.1720 {
1.1721 GstMessage *msg;
1.1722 nuv_frame_header h;
1.1723
1.1724 - while (gst_nuv_demux_frame_header_load (nuv, &h) == GST_FLOW_OK) {
1.1725 - if ((h.i_type == 'V') && (h.i_keyframe == 0)) {
1.1726 - frame_index_data *f = g_new0 (frame_index_data, 1);
1.1727 + while (gst_nuv_demux_frame_header_load(nuv, &h) == GST_FLOW_OK)
1.1728 + {
1.1729 + if ((h.i_type == 'V') && (h.i_keyframe == 0))
1.1730 + {
1.1731 + frame_index_data *f = g_new0(frame_index_data, 1);
1.1732
1.1733 - f->offset = nuv->priv->offset - 12;
1.1734 - f->timecode = h.i_timecode * GST_MSECOND;
1.1735 + f->offset = nuv->priv->offset - 12;
1.1736 + f->timecode = h.i_timecode * GST_MSECOND;
1.1737
1.1738 - nuv->priv->index = g_slist_append (nuv->priv->index, f);
1.1739 - }
1.1740 - if (h.i_type != 'R') {
1.1741 - nuv->priv->offset += h.i_length;
1.1742 + nuv->priv->index = g_slist_append(nuv->priv->index, f);
1.1743 + }
1.1744 + if (h.i_type != 'R')
1.1745 + {
1.1746 + nuv->priv->offset += h.i_length;
1.1747 if (h.i_type == 'A' || h.i_type == 'V')
1.1748 - nuv->priv->duration_time = h.i_timecode * GST_MSECOND;
1.1749 - }
1.1750 - }
1.1751 - GST_DEBUG_OBJECT (nuv, "CREATING INDEX: DONE : DURATION Bytes/Sec: %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
1.1752 - nuv->priv->offset, nuv->priv->duration_time);
1.1753 -
1.1754 + nuv->priv->duration_time = h.i_timecode * GST_MSECOND;
1.1755 + }
1.1756 + }
1.1757 + GST_DEBUG_OBJECT(nuv,
1.1758 + "CREATING INDEX: DONE : DURATION Bytes/Sec: %"
1.1759 + G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, nuv->priv->offset,
1.1760 + nuv->priv->duration_time);
1.1761 +
1.1762 nuv->priv->duration_bytes = nuv->priv->offset;
1.1763 nuv->priv->offset = nuv->priv->header_lengh;
1.1764
1.1765 - msg = gst_message_new_duration (GST_OBJECT (nuv), GST_FORMAT_TIME, nuv->priv->duration_time);
1.1766 - gst_element_post_message (GST_ELEMENT (nuv), msg);
1.1767 + msg =
1.1768 + gst_message_new_duration(GST_OBJECT(nuv), GST_FORMAT_TIME,
1.1769 + nuv->priv->duration_time);
1.1770 + gst_element_post_message(GST_ELEMENT(nuv), msg);
1.1771 }
1.1772
1.1773 static GstFlowReturn
1.1774 -gst_nuv_demux_play (GstPad * pad)
1.1775 +gst_nuv_demux_play(GstPad * pad)
1.1776 {
1.1777 GstFlowReturn res = GST_FLOW_OK;
1.1778 - GstNuvDemux *nuv = GST_NUV_DEMUX (GST_PAD_PARENT (pad));
1.1779 + GstNuvDemux *nuv = GST_NUV_DEMUX(GST_PAD_PARENT(pad));
1.1780
1.1781 - switch (nuv->priv->state) {
1.1782 - case GST_NUV_DEMUX_START:
1.1783 - res = gst_nuv_demux_stream_file_header (nuv);
1.1784 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1785 - goto pause;
1.1786 - }
1.1787 - break;
1.1788 + switch (nuv->priv->state)
1.1789 + {
1.1790 + case GST_NUV_DEMUX_START:
1.1791 + res = gst_nuv_demux_stream_file_header(nuv);
1.1792 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1793 + {
1.1794 + goto pause;
1.1795 + }
1.1796 + break;
1.1797
1.1798 - case GST_NUV_DEMUX_HEADER_DATA:
1.1799 - res = gst_nuv_demux_stream_header_data (nuv);
1.1800 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1801 - goto pause;
1.1802 - }
1.1803 - break;
1.1804 + case GST_NUV_DEMUX_HEADER_DATA:
1.1805 + res = gst_nuv_demux_stream_header_data(nuv);
1.1806 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1807 + {
1.1808 + goto pause;
1.1809 + }
1.1810 + break;
1.1811
1.1812 - case GST_NUV_DEMUX_EXTRA_DATA:
1.1813 - res = gst_nuv_demux_stream_extra_data (nuv);
1.1814 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1815 - goto pause;
1.1816 - }
1.1817 - break;
1.1818 + case GST_NUV_DEMUX_EXTRA_DATA:
1.1819 + res = gst_nuv_demux_stream_extra_data(nuv);
1.1820 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1821 + {
1.1822 + goto pause;
1.1823 + }
1.1824 + break;
1.1825
1.1826 - case GST_NUV_DEMUX_MPEG_DATA:
1.1827 - res = gst_nuv_demux_stream_mpeg_data (nuv);
1.1828 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1829 - goto pause;
1.1830 - }
1.1831 - break;
1.1832 + case GST_NUV_DEMUX_MPEG_DATA:
1.1833 + res = gst_nuv_demux_stream_mpeg_data(nuv);
1.1834 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1835 + {
1.1836 + goto pause;
1.1837 + }
1.1838 + break;
1.1839
1.1840 - case GST_NUV_DEMUX_EXTEND_HEADER:
1.1841 - res = gst_nuv_demux_stream_extend_header (nuv);
1.1842 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1843 - goto pause;
1.1844 - }
1.1845 - break;
1.1846 + case GST_NUV_DEMUX_EXTEND_HEADER:
1.1847 + res = gst_nuv_demux_stream_extend_header(nuv);
1.1848 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1849 + {
1.1850 + goto pause;
1.1851 + }
1.1852 + break;
1.1853
1.1854 - case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
1.1855 - res = gst_nuv_demux_stream_extend_header_data (nuv);
1.1856 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1857 - goto pause;
1.1858 - }
1.1859 - //store file header size
1.1860 - nuv->priv->header_lengh = nuv->priv->offset;
1.1861 - break;
1.1862 + case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
1.1863 + res = gst_nuv_demux_stream_extend_header_data(nuv);
1.1864 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1865 + {
1.1866 + goto pause;
1.1867 + }
1.1868 + //store file header size
1.1869 + nuv->priv->header_lengh = nuv->priv->offset;
1.1870 + break;
1.1871
1.1872 - case GST_NUV_DEMUX_INDEX_CREATE:
1.1873 - if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file)) {
1.1874 - gst_nuv_demux_create_seek_index (nuv);
1.1875 - }
1.1876 + case GST_NUV_DEMUX_INDEX_CREATE:
1.1877 + if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file))
1.1878 + {
1.1879 + gst_nuv_demux_create_seek_index(nuv);
1.1880 + }
1.1881
1.1882 - case GST_NUV_DEMUX_FRAME_HEADER:
1.1883 - res = gst_nuv_demux_read_head_frame (nuv);
1.1884 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1885 - goto pause;
1.1886 - }
1.1887 - break;
1.1888 + case GST_NUV_DEMUX_FRAME_HEADER:
1.1889 + res = gst_nuv_demux_read_head_frame(nuv);
1.1890 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1891 + {
1.1892 + goto pause;
1.1893 + }
1.1894 + break;
1.1895
1.1896 - case GST_NUV_DEMUX_MOVI:
1.1897 - res = gst_nuv_demux_stream_data (nuv);
1.1898 - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1.1899 - goto pause;
1.1900 - }
1.1901 - break;
1.1902 + case GST_NUV_DEMUX_MOVI:
1.1903 + res = gst_nuv_demux_stream_data(nuv);
1.1904 + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1.1905 + {
1.1906 + goto pause;
1.1907 + }
1.1908 + break;
1.1909
1.1910 - case GST_NUV_DEMUX_INVALID_DATA:
1.1911 - goto pause;
1.1912 - break;
1.1913 - default:
1.1914 - g_assert_not_reached ();
1.1915 - }
1.1916 + case GST_NUV_DEMUX_INVALID_DATA:
1.1917 + goto pause;
1.1918 + break;
1.1919 + default:
1.1920 + g_assert_not_reached();
1.1921 + }
1.1922
1.1923 return GST_FLOW_OK;
1.1924
1.1925 pause:
1.1926 - GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res));
1.1927 - gst_pad_pause_task (nuv->priv->sinkpad);
1.1928 + GST_LOG_OBJECT(nuv, "pausing task, reason %s", gst_flow_get_name(res));
1.1929 + gst_pad_pause_task(nuv->priv->sinkpad);
1.1930
1.1931 - if (res == GST_FLOW_ERROR_EOS) {
1.1932 - gst_nuv_demux_send_eos (nuv);
1.1933 - nuv->priv->eos = TRUE;
1.1934 - res = GST_FLOW_OK;
1.1935 - }
1.1936 + if (res == GST_FLOW_ERROR_EOS)
1.1937 + {
1.1938 + gst_nuv_demux_send_eos(nuv);
1.1939 + nuv->priv->eos = TRUE;
1.1940 + res = GST_FLOW_OK;
1.1941 + }
1.1942
1.1943 - if (GST_FLOW_IS_FATAL (res)) {
1.1944 - GST_ELEMENT_ERROR (nuv, STREAM, FAILED,
1.1945 - (_("Internal data stream error.")),
1.1946 - ("streaming stopped, reason %s", gst_flow_get_name (res)));
1.1947 + if (GST_FLOW_IS_FATAL(res))
1.1948 + {
1.1949 + GST_ELEMENT_ERROR(nuv, STREAM, FAILED,
1.1950 + (_("Internal data stream error.")),
1.1951 + ("streaming stopped, reason %s",
1.1952 + gst_flow_get_name(res)));
1.1953
1.1954 - gst_nuv_demux_send_eos (nuv);
1.1955 - }
1.1956 + gst_nuv_demux_send_eos(nuv);
1.1957 + }
1.1958 return res;
1.1959 }
1.1960
1.1961 static void
1.1962 -gst_nuv_demux_send_eos (GstNuvDemux * nuv)
1.1963 +gst_nuv_demux_send_eos(GstNuvDemux * nuv)
1.1964 {
1.1965 - gst_element_post_message (GST_ELEMENT (nuv),
1.1966 - gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1));
1.1967 + gst_element_post_message(GST_ELEMENT(nuv),
1.1968 + gst_message_new_segment_done(GST_OBJECT(nuv),
1.1969 + GST_FORMAT_TIME, -1));
1.1970
1.1971 if (nuv->priv->src_video_pad)
1.1972 - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_eos ());
1.1973 + gst_pad_push_event(nuv->priv->src_video_pad, gst_event_new_eos());
1.1974 if (nuv->priv->src_audio_pad)
1.1975 - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_eos ());
1.1976 + gst_pad_push_event(nuv->priv->src_audio_pad, gst_event_new_eos());
1.1977 }
1.1978
1.1979 static GstFlowReturn
1.1980 -gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, gboolean move,
1.1981 - GstBuffer ** buffer)
1.1982 +gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size, gboolean move,
1.1983 + GstBuffer ** buffer)
1.1984 {
1.1985 GstFlowReturn ret = GST_FLOW_OK;
1.1986
1.1987 - if (size == 0) {
1.1988 - return ret;
1.1989 - }
1.1990 + if (size == 0)
1.1991 + {
1.1992 + return ret;
1.1993 + }
1.1994
1.1995 - if (nuv->priv->mode == NUV_PULL_MODE) {
1.1996 - ret = gst_pad_pull_range (nuv->priv->sinkpad, nuv->priv->offset, size, buffer);
1.1997 - if (ret == GST_FLOW_OK) {
1.1998 - if (move) {
1.1999 - nuv->priv->offset += size;
1.2000 - }
1.2001 - /* got eos */
1.2002 - } else if (ret == GST_FLOW_UNEXPECTED) {
1.2003 - return GST_FLOW_ERROR_EOS;
1.2004 - }
1.2005 - } else {
1.2006 - if (gst_adapter_available (nuv->priv->adapter) < size) {
1.2007 - nuv->priv->more_data = TRUE;
1.2008 - return GST_FLOW_ERROR_NO_DATA;
1.2009 - }
1.2010 - if (move) {
1.2011 - *buffer = gst_adapter_take_buffer (nuv->priv->adapter, size);
1.2012 - } else {
1.2013 - guint8 *data = NULL;
1.2014 - data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size);
1.2015 - *buffer = gst_buffer_new ();
1.2016 - gst_buffer_set_data (*buffer, data, size);
1.2017 - }
1.2018 - }
1.2019 + if (nuv->priv->mode == NUV_PULL_MODE)
1.2020 + {
1.2021 + ret =
1.2022 + gst_pad_pull_range(nuv->priv->sinkpad, nuv->priv->offset, size,
1.2023 + buffer);
1.2024 + if (ret == GST_FLOW_OK)
1.2025 + {
1.2026 + if (move)
1.2027 + {
1.2028 + nuv->priv->offset += size;
1.2029 + }
1.2030 + /* got eos */
1.2031 + }
1.2032 + else if (ret == GST_FLOW_UNEXPECTED)
1.2033 + {
1.2034 + return GST_FLOW_ERROR_EOS;
1.2035 + }
1.2036 + }
1.2037 + else
1.2038 + {
1.2039 + if (gst_adapter_available(nuv->priv->adapter) < size)
1.2040 + {
1.2041 + nuv->priv->more_data = TRUE;
1.2042 + return GST_FLOW_ERROR_NO_DATA;
1.2043 + }
1.2044 + if (move)
1.2045 + {
1.2046 + *buffer = gst_adapter_take_buffer(nuv->priv->adapter, size);
1.2047 + }
1.2048 + else
1.2049 + {
1.2050 + guint8 *data = NULL;
1.2051 + data = (guint8 *) gst_adapter_peek(nuv->priv->adapter, size);
1.2052 + *buffer = gst_buffer_new();
1.2053 + gst_buffer_set_data(*buffer, data, size);
1.2054 + }
1.2055 + }
1.2056 return ret;
1.2057 }
1.2058
1.2059 static GstFlowReturn
1.2060 -gst_nuv_demux_move_bytes (GstNuvDemux * nuv, guint64 size)
1.2061 +gst_nuv_demux_move_bytes(GstNuvDemux * nuv, guint64 size)
1.2062 {
1.2063 GstFlowReturn ret = GST_FLOW_OK;
1.2064
1.2065 - if (size == 0) {
1.2066 - return ret;
1.2067 - }
1.2068 + if (size == 0)
1.2069 + {
1.2070 + return ret;
1.2071 + }
1.2072
1.2073 - if (nuv->priv->mode == NUV_PULL_MODE) {
1.2074 - nuv->priv->offset += size;
1.2075 - } else {
1.2076 - if (gst_adapter_available (nuv->priv->adapter) < size) {
1.2077 - nuv->priv->more_data = TRUE;
1.2078 - return GST_FLOW_ERROR_NO_DATA;
1.2079 - }
1.2080 - gst_adapter_flush (nuv->priv->adapter, size);
1.2081 - }
1.2082 + if (nuv->priv->mode == NUV_PULL_MODE)
1.2083 + {
1.2084 + nuv->priv->offset += size;
1.2085 + }
1.2086 + else
1.2087 + {
1.2088 + if (gst_adapter_available(nuv->priv->adapter) < size)
1.2089 + {
1.2090 + nuv->priv->more_data = TRUE;
1.2091 + return GST_FLOW_ERROR_NO_DATA;
1.2092 + }
1.2093 + gst_adapter_flush(nuv->priv->adapter, size);
1.2094 + }
1.2095 return ret;
1.2096 }
1.2097
1.2098 static gboolean
1.2099 -gst_nuv_demux_sink_activate (GstPad * sinkpad)
1.2100 +gst_nuv_demux_sink_activate(GstPad * sinkpad)
1.2101 {
1.2102 gboolean res = TRUE;
1.2103 - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
1.2104 -
1.2105 - if (gst_pad_check_pull_range (sinkpad)) {
1.2106 - gst_adapter_clear (nuv->priv->adapter);
1.2107 - res = gst_pad_activate_pull (sinkpad, TRUE);
1.2108 - } else {
1.2109 - gst_adapter_clear (nuv->priv->adapter);
1.2110 - res = gst_pad_activate_push (sinkpad, TRUE);
1.2111 - }
1.2112 -
1.2113 - g_object_unref (nuv);
1.2114 + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad));
1.2115 +
1.2116 + if (gst_pad_check_pull_range(sinkpad))
1.2117 + {
1.2118 + gst_adapter_clear(nuv->priv->adapter);
1.2119 + res = gst_pad_activate_pull(sinkpad, TRUE);
1.2120 + }
1.2121 + else
1.2122 + {
1.2123 + gst_adapter_clear(nuv->priv->adapter);
1.2124 + res = gst_pad_activate_push(sinkpad, TRUE);
1.2125 + }
1.2126 +
1.2127 + g_object_unref(nuv);
1.2128 return res;
1.2129 }
1.2130
1.2131 static gboolean
1.2132 -gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
1.2133 +gst_nuv_demux_sink_activate_pull(GstPad * sinkpad, gboolean active)
1.2134 {
1.2135 - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
1.2136 + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad));
1.2137
1.2138 - if (active) {
1.2139 - GST_DEBUG_OBJECT (nuv, "activating pull function");
1.2140 - nuv->priv->mode = NUV_PULL_MODE;
1.2141 - gst_adapter_clear (nuv->priv->adapter);
1.2142 + if (active)
1.2143 + {
1.2144 + GST_DEBUG_OBJECT(nuv, "activating pull function");
1.2145 + nuv->priv->mode = NUV_PULL_MODE;
1.2146 + gst_adapter_clear(nuv->priv->adapter);
1.2147
1.2148 - gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
1.2149 - } else {
1.2150 - GST_DEBUG_OBJECT (nuv, "deactivating pull function");
1.2151 - gst_pad_stop_task (sinkpad);
1.2152 - }
1.2153 - gst_object_unref (nuv);
1.2154 + gst_pad_start_task(sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1.2155 + sinkpad);
1.2156 + }
1.2157 + else
1.2158 + {
1.2159 + GST_DEBUG_OBJECT(nuv, "deactivating pull function");
1.2160 + gst_pad_stop_task(sinkpad);
1.2161 + }
1.2162 + gst_object_unref(nuv);
1.2163
1.2164 return TRUE;
1.2165 }
1.2166
1.2167 static gboolean
1.2168 -gst_nuv_demux_sink_activate_push (GstPad * pad, gboolean active)
1.2169 +gst_nuv_demux_sink_activate_push(GstPad * pad, gboolean active)
1.2170 {
1.2171 - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1.2172 + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1.2173
1.2174 - if (active) {
1.2175 - nuv->priv->mode = NUV_PUSH_MODE;
1.2176 - gst_adapter_clear (nuv->priv->adapter);
1.2177 + if (active)
1.2178 + {
1.2179 + nuv->priv->mode = NUV_PUSH_MODE;
1.2180 + gst_adapter_clear(nuv->priv->adapter);
1.2181
1.2182 - GST_DEBUG_OBJECT (nuv, "activating push/chain function");
1.2183 - } else {
1.2184 - GST_DEBUG_OBJECT (nuv, "deactivating push/chain function");
1.2185 - }
1.2186 + GST_DEBUG_OBJECT(nuv, "activating push/chain function");
1.2187 + }
1.2188 + else
1.2189 + {
1.2190 + GST_DEBUG_OBJECT(nuv, "deactivating push/chain function");
1.2191 + }
1.2192
1.2193 - gst_object_unref (nuv);
1.2194 + gst_object_unref(nuv);
1.2195
1.2196 return TRUE;
1.2197 }
1.2198
1.2199 static frame_index_data *
1.2200 -gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos,
1.2201 - gint64 segment_stop, GstFormat format)
1.2202 +gst_nuv_demux_do_seek_index(GstNuvDemux * nuv, gint64 seek_pos,
1.2203 + gint64 segment_stop, GstFormat format)
1.2204 {
1.2205 GSList *l;
1.2206 frame_index_data *ret = NULL;
1.2207
1.2208 - if (nuv->priv->index == NULL) {
1.2209 - return NULL;
1.2210 - }
1.2211 + if (nuv->priv->index == NULL)
1.2212 + {
1.2213 + return NULL;
1.2214 + }
1.2215
1.2216 - /* find keyframe closest to the requested position */
1.2217 - for (l = nuv->priv->index; l != NULL; l = l->next) {
1.2218 - frame_index_data *f = (frame_index_data *) l->data;
1.2219 - gint64 pos = 0;
1.2220 -
1.2221 - if (format == GST_FORMAT_BYTES) {
1.2222 - pos = f->offset;
1.2223 - } else if (format == GST_FORMAT_TIME) {
1.2224 - pos = f->timecode;
1.2225 - } else {
1.2226 - return NULL;
1.2227 - }
1.2228 + /* find keyframe closest to the requested position */
1.2229 + for (l = nuv->priv->index; l != NULL; l = l->next)
1.2230 + {
1.2231 + frame_index_data *f = (frame_index_data *) l->data;
1.2232 + gint64 pos = 0;
1.2233
1.2234 - if (pos >= seek_pos) {
1.2235 - ret = f;
1.2236 - break;
1.2237 - }
1.2238 + if (format == GST_FORMAT_BYTES)
1.2239 + {
1.2240 + pos = f->offset;
1.2241 + }
1.2242 + else if (format == GST_FORMAT_TIME)
1.2243 + {
1.2244 + pos = f->timecode;
1.2245 + }
1.2246 + else
1.2247 + {
1.2248 + return NULL;
1.2249 + }
1.2250
1.2251 - if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE) && (pos > segment_stop)) {
1.2252 - break;
1.2253 - }
1.2254 - }
1.2255 + if (pos >= seek_pos)
1.2256 + {
1.2257 + ret = f;
1.2258 + break;
1.2259 + }
1.2260 +
1.2261 + if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE)
1.2262 + && (pos > segment_stop))
1.2263 + {
1.2264 + break;
1.2265 + }
1.2266 + }
1.2267
1.2268 return ret;
1.2269 }
1.2270
1.2271 static gboolean
1.2272 -gst_nuv_demux_do_seek (GstNuvDemux *nuv, GstEvent * event)
1.2273 +gst_nuv_demux_do_seek(GstNuvDemux * nuv, GstEvent * event)
1.2274 {
1.2275 gdouble rate;
1.2276 GstFormat format;
1.2277 @@ -1381,17 +1550,19 @@
1.2278 gint64 segment_stop;
1.2279 GstEvent *newsegment_event;
1.2280
1.2281 - if (nuv->priv->eos) {
1.2282 - return FALSE;
1.2283 - }
1.2284 + if (nuv->priv->eos)
1.2285 + {
1.2286 + return FALSE;
1.2287 + }
1.2288
1.2289 - if (nuv->priv->mode == NUV_PUSH_MODE) {
1.2290 - return FALSE;
1.2291 - }
1.2292 + if (nuv->priv->mode == NUV_PUSH_MODE)
1.2293 + {
1.2294 + return FALSE;
1.2295 + }
1.2296
1.2297
1.2298 - gst_event_parse_seek (event, &rate, &format, &flags,
1.2299 - &cur_type, &cur, &stop_type, &stop);
1.2300 + gst_event_parse_seek(event, &rate, &format, &flags,
1.2301 + &cur_type, &cur, &stop_type, &stop);
1.2302
1.2303
1.2304
1.2305 @@ -1402,249 +1573,277 @@
1.2306 }
1.2307 */
1.2308
1.2309 - if (rate <= 0.0) {
1.2310 - GST_DEBUG_OBJECT (nuv, "Can only seek with positive rate");
1.2311 - return FALSE;
1.2312 - }
1.2313 -
1.2314 - if (cur_type == GST_SEEK_TYPE_SET) {
1.2315 - GST_OBJECT_LOCK (nuv);
1.2316 - if (gst_nuv_demux_do_seek_index (nuv, cur, -1, format) == NULL) {
1.2317 - GST_DEBUG_OBJECT (nuv, "No matching seek entry in index");
1.2318 - GST_OBJECT_UNLOCK (nuv);
1.2319 - return FALSE;
1.2320 - }
1.2321 - GST_OBJECT_UNLOCK (nuv);
1.2322 - }
1.2323 + if (rate <= 0.0)
1.2324 + {
1.2325 + GST_DEBUG_OBJECT(nuv, "Can only seek with positive rate");
1.2326 + return FALSE;
1.2327 + }
1.2328 +
1.2329 + if (cur_type == GST_SEEK_TYPE_SET)
1.2330 + {
1.2331 + GST_OBJECT_LOCK(nuv);
1.2332 + if (gst_nuv_demux_do_seek_index(nuv, cur, -1, format) == NULL)
1.2333 + {
1.2334 + GST_DEBUG_OBJECT(nuv, "No matching seek entry in index");
1.2335 + GST_OBJECT_UNLOCK(nuv);
1.2336 + return FALSE;
1.2337 + }
1.2338 + GST_OBJECT_UNLOCK(nuv);
1.2339 + }
1.2340
1.2341 flush = !!(flags & GST_SEEK_FLAG_FLUSH);
1.2342 -
1.2343 - if (flush) {
1.2344 - gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_start ());
1.2345 - if (nuv->priv->src_video_pad != NULL) {
1.2346 - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_start ());
1.2347 - }
1.2348
1.2349 - if (nuv->priv->src_audio_pad != NULL) {
1.2350 - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_start ());
1.2351 - }
1.2352 - }
1.2353 - else {
1.2354 - gst_pad_pause_task (nuv->priv->sinkpad);
1.2355 - }
1.2356 + if (flush)
1.2357 + {
1.2358 + gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_start());
1.2359 + if (nuv->priv->src_video_pad != NULL)
1.2360 + {
1.2361 + gst_pad_push_event(nuv->priv->src_video_pad,
1.2362 + gst_event_new_flush_start());
1.2363 + }
1.2364
1.2365 - GST_PAD_STREAM_LOCK (nuv->priv->sinkpad);
1.2366 - GST_OBJECT_LOCK (nuv);
1.2367 + if (nuv->priv->src_audio_pad != NULL)
1.2368 + {
1.2369 + gst_pad_push_event(nuv->priv->src_audio_pad,
1.2370 + gst_event_new_flush_start());
1.2371 + }
1.2372 + }
1.2373 + else
1.2374 + {
1.2375 + gst_pad_pause_task(nuv->priv->sinkpad);
1.2376 + }
1.2377 +
1.2378 + GST_PAD_STREAM_LOCK(nuv->priv->sinkpad);
1.2379 + GST_OBJECT_LOCK(nuv);
1.2380
1.2381
1.2382 if (cur == GST_CLOCK_TIME_NONE)
1.2383 - cur = 0;
1.2384 + cur = 0;
1.2385 if (stop == GST_CLOCK_TIME_NONE)
1.2386 - stop = nuv->priv->duration_time;
1.2387 + stop = nuv->priv->duration_time;
1.2388
1.2389 if (cur_type == GST_SEEK_TYPE_SET)
1.2390 - segment_start = cur;
1.2391 + segment_start = cur;
1.2392 else if (cur_type == GST_SEEK_TYPE_CUR)
1.2393 - segment_start = nuv->priv->segment_start + cur;
1.2394 + segment_start = nuv->priv->segment_start + cur;
1.2395 else
1.2396 - segment_start = nuv->priv->segment_start;
1.2397 + segment_start = nuv->priv->segment_start;
1.2398
1.2399 if (stop_type == GST_SEEK_TYPE_SET)
1.2400 - segment_stop = stop;
1.2401 + segment_stop = stop;
1.2402 else if (stop_type == GST_SEEK_TYPE_CUR)
1.2403 - segment_stop = nuv->priv->segment_stop + stop;
1.2404 + segment_stop = nuv->priv->segment_stop + stop;
1.2405 else
1.2406 - segment_stop = nuv->priv->segment_stop;
1.2407 + segment_stop = nuv->priv->segment_stop;
1.2408
1.2409 - segment_start = CLAMP (segment_start, 0, nuv->priv->duration_time);
1.2410 - segment_stop = CLAMP (segment_stop, 0, nuv->priv->duration_time);
1.2411 + segment_start = CLAMP(segment_start, 0, nuv->priv->duration_time);
1.2412 + segment_stop = CLAMP(segment_stop, 0, nuv->priv->duration_time);
1.2413
1.2414 - entry = gst_nuv_demux_do_seek_index (nuv, segment_start,
1.2415 - segment_stop, format);
1.2416 + entry = gst_nuv_demux_do_seek_index(nuv, segment_start,
1.2417 + segment_stop, format);
1.2418
1.2419 - if (entry == NULL) {
1.2420 - GST_DEBUG_OBJECT (nuv, "No matching seek entry in index");
1.2421 - goto seek_error;
1.2422 - }
1.2423 + if (entry == NULL)
1.2424 + {
1.2425 + GST_DEBUG_OBJECT(nuv, "No matching seek entry in index");
1.2426 + goto seek_error;
1.2427 + }
1.2428
1.2429 segment_start = entry->timecode;
1.2430
1.2431 nuv->priv->segment_start = segment_start;
1.2432 nuv->priv->segment_stop = segment_stop;
1.2433
1.2434 - GST_OBJECT_UNLOCK (nuv);
1.2435 + GST_OBJECT_UNLOCK(nuv);
1.2436
1.2437 - if (!nuv->priv->eos) {
1.2438 - GstMessage *msg;
1.2439 - msg = gst_message_new_segment_start (GST_OBJECT (nuv), GST_FORMAT_TIME,
1.2440 - nuv->priv->segment_start);
1.2441 -
1.2442 - gst_element_post_message (GST_ELEMENT (nuv), msg);
1.2443 - }
1.2444 + if (!nuv->priv->eos)
1.2445 + {
1.2446 + GstMessage *msg;
1.2447 + msg = gst_message_new_segment_start(GST_OBJECT(nuv), GST_FORMAT_TIME,
1.2448 + nuv->priv->segment_start);
1.2449
1.2450 - GST_DEBUG_OBJECT (nuv, "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %" G_GUINT64_FORMAT,
1.2451 - segment_start, segment_stop);
1.2452 - newsegment_event = gst_event_new_new_segment (FALSE, rate,
1.2453 - GST_FORMAT_TIME, segment_start, segment_stop, segment_start);
1.2454 + gst_element_post_message(GST_ELEMENT(nuv), msg);
1.2455 + }
1.2456
1.2457 + GST_DEBUG_OBJECT(nuv,
1.2458 + "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %"
1.2459 + G_GUINT64_FORMAT, segment_start, segment_stop);
1.2460 + newsegment_event =
1.2461 + gst_event_new_new_segment(FALSE, rate, GST_FORMAT_TIME, segment_start,
1.2462 + segment_stop, segment_start);
1.2463
1.2464 - if (flush) {
1.2465 - if (nuv->priv->src_video_pad != NULL) {
1.2466 - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_stop ());
1.2467 - }
1.2468
1.2469 - if (nuv->priv->src_audio_pad != NULL) {
1.2470 - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_stop ());
1.2471 - }
1.2472 + if (flush)
1.2473 + {
1.2474 + if (nuv->priv->src_video_pad != NULL)
1.2475 + {
1.2476 + gst_pad_push_event(nuv->priv->src_video_pad,
1.2477 + gst_event_new_flush_stop());
1.2478 + }
1.2479
1.2480 - gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_stop ());
1.2481 - }
1.2482 + if (nuv->priv->src_audio_pad != NULL)
1.2483 + {
1.2484 + gst_pad_push_event(nuv->priv->src_audio_pad,
1.2485 + gst_event_new_flush_stop());
1.2486 + }
1.2487
1.2488 -
1.2489 - if (nuv->priv->src_video_pad != NULL) {
1.2490 - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
1.2491 - }
1.2492 - if (nuv->priv->src_audio_pad != NULL) {
1.2493 - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
1.2494 - }
1.2495 + gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_stop());
1.2496 + }
1.2497
1.2498 - gst_event_unref (newsegment_event);
1.2499 +
1.2500 + if (nuv->priv->src_video_pad != NULL)
1.2501 + {
1.2502 + gst_pad_push_event(nuv->priv->src_video_pad,
1.2503 + gst_event_ref(newsegment_event));
1.2504 + }
1.2505 + if (nuv->priv->src_audio_pad != NULL)
1.2506 + {
1.2507 + gst_pad_push_event(nuv->priv->src_audio_pad,
1.2508 + gst_event_ref(newsegment_event));
1.2509 + }
1.2510 +
1.2511 + gst_event_unref(newsegment_event);
1.2512
1.2513 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1.2514 nuv->priv->offset = entry->offset;
1.2515
1.2516 - gst_pad_start_task (nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1.2517 - nuv->priv->sinkpad);
1.2518 + gst_pad_start_task(nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1.2519 + nuv->priv->sinkpad);
1.2520
1.2521 - GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad);
1.2522 + GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad);
1.2523 return TRUE;
1.2524
1.2525 seek_error:
1.2526 - GST_DEBUG_OBJECT (nuv, "Got a seek error");
1.2527 - GST_OBJECT_UNLOCK (nuv);
1.2528 - GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad);
1.2529 + GST_DEBUG_OBJECT(nuv, "Got a seek error");
1.2530 + GST_OBJECT_UNLOCK(nuv);
1.2531 + GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad);
1.2532 return FALSE;
1.2533
1.2534 }
1.2535
1.2536 static gboolean
1.2537 -gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event)
1.2538 +gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event)
1.2539 {
1.2540 gboolean res = FALSE;
1.2541 GstNuvDemux *nuv;
1.2542
1.2543 - nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1.2544 -
1.2545 - switch (GST_EVENT_TYPE (event)) {
1.2546 - case GST_EVENT_SEEK:
1.2547 - res = gst_nuv_demux_do_seek (nuv, event);
1.2548 - break;
1.2549 - default:
1.2550 - res = FALSE;
1.2551 - break;
1.2552 - }
1.2553 -
1.2554 - gst_object_unref (nuv);
1.2555 + nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1.2556 +
1.2557 + switch (GST_EVENT_TYPE(event))
1.2558 + {
1.2559 + case GST_EVENT_SEEK:
1.2560 + res = gst_nuv_demux_do_seek(nuv, event);
1.2561 + break;
1.2562 + default:
1.2563 + res = FALSE;
1.2564 + break;
1.2565 + }
1.2566 +
1.2567 + gst_object_unref(nuv);
1.2568 return res;
1.2569 }
1.2570
1.2571 static gboolean
1.2572 -gst_nuv_demux_sink_event (GstPad * pad, GstEvent * event)
1.2573 +gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event)
1.2574 {
1.2575 - gboolean res = FALSE;
1.2576 - GstNuvDemux *nuv;
1.2577 + gboolean res = FALSE;
1.2578 + GstNuvDemux *nuv;
1.2579
1.2580 - nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1.2581 -
1.2582 - switch (GST_EVENT_TYPE (event)) {
1.2583 - case GST_EVENT_NEWSEGMENT:
1.2584 - {
1.2585 - gboolean update;
1.2586 - gdouble rate;
1.2587 - GstFormat format;
1.2588 - gint64 start;
1.2589 - gint64 stop;
1.2590 - gint64 position;
1.2591 + nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1.2592
1.2593 - gst_event_parse_new_segment (event, &update, &rate, &format, &start, &stop, &position);
1.2594 - if ((format == GST_FORMAT_BYTES) && (start == 0)) {
1.2595 - g_debug ("NEW SEGMENT 0");
1.2596 - if (nuv->priv->segment > 0) {
1.2597 - nuv->priv->new_file = TRUE;
1.2598 - nuv->priv->state = GST_NUV_DEMUX_START;
1.2599 - nuv->priv->offset = 0;
1.2600 - }
1.2601 - nuv->priv->segment++;
1.2602 + switch (GST_EVENT_TYPE(event))
1.2603 + {
1.2604 + case GST_EVENT_NEWSEGMENT:
1.2605 + {
1.2606 + gboolean update;
1.2607 + gdouble rate;
1.2608 + GstFormat format;
1.2609 + gint64 start;
1.2610 + gint64 stop;
1.2611 + gint64 position;
1.2612
1.2613 - /*
1.2614 - newsegment_event = gst_event_new_new_segment (FALSE, rate,
1.2615 - GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
1.2616 + gst_event_parse_new_segment(event, &update, &rate, &format, &start,
1.2617 + &stop, &position);
1.2618 + if ((format == GST_FORMAT_BYTES) && (start == 0))
1.2619 + {
1.2620 + g_debug("NEW SEGMENT 0");
1.2621 + if (nuv->priv->segment > 0)
1.2622 + {
1.2623 + nuv->priv->new_file = TRUE;
1.2624 + nuv->priv->state = GST_NUV_DEMUX_START;
1.2625 + nuv->priv->offset = 0;
1.2626 + }
1.2627 + nuv->priv->segment++;
1.2628
1.2629 - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
1.2630 - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
1.2631 - gst_event_unref (newsegment_event);
1.2632 - */
1.2633 - res = gst_pad_event_default(pad, event);
1.2634 - }
1.2635 - break;
1.2636 - }
1.2637 - case GST_EVENT_CUSTOM_DOWNSTREAM:
1.2638 - {
1.2639 - /*
1.2640 - nuv->priv->new_file = TRUE;
1.2641 - nuv->priv->state = GST_NUV_DEMUX_START;
1.2642 - nuv->priv->offset = 0;
1.2643 - */
1.2644 - GST_PAD_STREAM_LOCK (pad);
1.2645 - gst_nuv_demux_reset( nuv );
1.2646 - GST_PAD_STREAM_UNLOCK (pad);
1.2647 + /*
1.2648 + newsegment_event = gst_event_new_new_segment (FALSE, rate,
1.2649 + GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
1.2650
1.2651 - res = gst_pad_event_default (pad, event);
1.2652 - break;
1.2653 - }
1.2654 - default:
1.2655 - res = gst_pad_event_default (pad, event);
1.2656 - break;
1.2657 - }
1.2658 + gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
1.2659 + gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
1.2660 + gst_event_unref (newsegment_event);
1.2661 + */
1.2662 + res = gst_pad_event_default(pad, event);
1.2663 + }
1.2664 + break;
1.2665 + }
1.2666 + case GST_EVENT_CUSTOM_DOWNSTREAM:
1.2667 + {
1.2668 + /*
1.2669 + nuv->priv->new_file = TRUE;
1.2670 + nuv->priv->state = GST_NUV_DEMUX_START;
1.2671 + nuv->priv->offset = 0;
1.2672 + */
1.2673 + GST_PAD_STREAM_LOCK(pad);
1.2674 + gst_nuv_demux_reset(nuv);
1.2675 + GST_PAD_STREAM_UNLOCK(pad);
1.2676
1.2677 - return res;
1.2678 + res = gst_pad_event_default(pad, event);
1.2679 + break;
1.2680 + }
1.2681 + default:
1.2682 + res = gst_pad_event_default(pad, event);
1.2683 + break;
1.2684 + }
1.2685 +
1.2686 + return res;
1.2687 }
1.2688
1.2689 static GstFlowReturn
1.2690 -gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
1.2691 +gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf)
1.2692 {
1.2693 GstFlowReturn ret = GST_FLOW_OK;
1.2694 - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1.2695 -
1.2696 + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1.2697 +
1.2698 if (nuv->priv->mode != NUV_PUSH_MODE)
1.2699 - return ret;
1.2700 + return ret;
1.2701
1.2702 - gst_adapter_push (nuv->priv->adapter, buf);
1.2703 -
1.2704 - while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE)) {
1.2705 - ret = gst_nuv_demux_play (pad);
1.2706 - }
1.2707 + gst_adapter_push(nuv->priv->adapter, buf);
1.2708 +
1.2709 + while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE))
1.2710 + {
1.2711 + ret = gst_nuv_demux_play(pad);
1.2712 + }
1.2713
1.2714 nuv->priv->more_data = FALSE;
1.2715 - gst_object_unref (nuv);
1.2716 + gst_object_unref(nuv);
1.2717
1.2718 return ret;
1.2719 }
1.2720
1.2721 static void
1.2722 -gst_nuv_demux_loop (GstPad * pad)
1.2723 +gst_nuv_demux_loop(GstPad * pad)
1.2724 {
1.2725 - gst_nuv_demux_play (pad);
1.2726 + gst_nuv_demux_play(pad);
1.2727 }
1.2728
1.2729 static void
1.2730 -gst_nuv_demux_index_free (gpointer data, gpointer user_data)
1.2731 +gst_nuv_demux_index_free(gpointer data, gpointer user_data)
1.2732 {
1.2733 - g_free (data);
1.2734 + g_free(data);
1.2735 }
1.2736
1.2737 static void
1.2738 -gst_nuv_demux_reset (GstNuvDemux * nuv)
1.2739 +gst_nuv_demux_reset(GstNuvDemux * nuv)
1.2740 {
1.2741 nuv->priv->eos = FALSE;
1.2742 nuv->priv->more_data = FALSE;
1.2743 @@ -1662,160 +1861,172 @@
1.2744 nuv->priv->segment_start = GST_CLOCK_TIME_NONE;
1.2745 nuv->priv->new_file = FALSE;
1.2746
1.2747 - //clear index list
1.2748 - g_slist_foreach (nuv->priv->index, gst_nuv_demux_index_free, NULL);
1.2749 - g_slist_free (nuv->priv->index);
1.2750 + //clear index list
1.2751 + g_slist_foreach(nuv->priv->index, gst_nuv_demux_index_free, NULL);
1.2752 + g_slist_free(nuv->priv->index);
1.2753 nuv->priv->index = NULL;
1.2754
1.2755 - gst_adapter_clear (nuv->priv->adapter);
1.2756 + gst_adapter_clear(nuv->priv->adapter);
1.2757
1.2758 - if (nuv->priv->mpeg_buffer != NULL) {
1.2759 - gst_buffer_unref (nuv->priv->mpeg_buffer);
1.2760 - nuv->priv->mpeg_buffer = NULL;
1.2761 - }
1.2762 + if (nuv->priv->mpeg_buffer != NULL)
1.2763 + {
1.2764 + gst_buffer_unref(nuv->priv->mpeg_buffer);
1.2765 + nuv->priv->mpeg_buffer = NULL;
1.2766 + }
1.2767 }
1.2768
1.2769 static void
1.2770 -gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv)
1.2771 +gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv)
1.2772 {
1.2773 - if (nuv->priv->src_video_pad) {
1.2774 - gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_video_pad);
1.2775 - nuv->priv->src_video_pad = NULL;
1.2776 - }
1.2777 + if (nuv->priv->src_video_pad)
1.2778 + {
1.2779 + gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_video_pad);
1.2780 + nuv->priv->src_video_pad = NULL;
1.2781 + }
1.2782
1.2783 - if (nuv->priv->src_audio_pad) {
1.2784 - gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_audio_pad);
1.2785 - nuv->priv->src_audio_pad = NULL;
1.2786 - }
1.2787 + if (nuv->priv->src_audio_pad)
1.2788 + {
1.2789 + gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_audio_pad);
1.2790 + nuv->priv->src_audio_pad = NULL;
1.2791 + }
1.2792 }
1.2793
1.2794 static GstStateChangeReturn
1.2795 -gst_nuv_demux_change_state (GstElement * element, GstStateChange transition)
1.2796 +gst_nuv_demux_change_state(GstElement * element, GstStateChange transition)
1.2797 {
1.2798 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1.2799
1.2800 - g_debug ("Nuvdemux state_change");
1.2801 - switch (transition) {
1.2802 - case GST_STATE_CHANGE_NULL_TO_READY:
1.2803 - gst_nuv_demux_reset (GST_NUV_DEMUX (element));
1.2804 - gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
1.2805 - break;
1.2806 - default:
1.2807 - break;
1.2808 - }
1.2809 + g_debug("Nuvdemux state_change");
1.2810 + switch (transition)
1.2811 + {
1.2812 + case GST_STATE_CHANGE_NULL_TO_READY:
1.2813 + gst_nuv_demux_reset(GST_NUV_DEMUX(element));
1.2814 + gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element));
1.2815 + break;
1.2816 + default:
1.2817 + break;
1.2818 + }
1.2819
1.2820 - g_debug ("Nuvdemux state_change: 1");
1.2821 + g_debug("Nuvdemux state_change: 1");
1.2822
1.2823 - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1.2824 - if (ret == GST_STATE_CHANGE_FAILURE) {
1.2825 - goto done;
1.2826 - }
1.2827 + ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1.2828 + if (ret == GST_STATE_CHANGE_FAILURE)
1.2829 + {
1.2830 + goto done;
1.2831 + }
1.2832
1.2833
1.2834 - g_debug ("Nuvdemux state_change: 2");
1.2835 + g_debug("Nuvdemux state_change: 2");
1.2836
1.2837 - switch (transition) {
1.2838 - case GST_STATE_CHANGE_READY_TO_NULL:
1.2839 - gst_nuv_demux_reset (GST_NUV_DEMUX (element));
1.2840 - gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
1.2841 - break;
1.2842 - default:
1.2843 - break;
1.2844 - }
1.2845 + switch (transition)
1.2846 + {
1.2847 + case GST_STATE_CHANGE_READY_TO_NULL:
1.2848 + gst_nuv_demux_reset(GST_NUV_DEMUX(element));
1.2849 + gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element));
1.2850 + break;
1.2851 + default:
1.2852 + break;
1.2853 + }
1.2854
1.2855
1.2856 - g_debug ("Nuvdemux state_change: DONE");
1.2857 + g_debug("Nuvdemux state_change: DONE");
1.2858
1.2859 done:
1.2860 return ret;
1.2861 }
1.2862
1.2863 -#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1.2864 +#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1.2865 GstBuffer *
1.2866 -gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
1.2867 +gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes)
1.2868 {
1.2869 GstBuffer *buffer;
1.2870 GstBuffer *cur;
1.2871 guint8 *data;
1.2872
1.2873 - g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1.2874 - g_return_val_if_fail (nbytes > 0, NULL);
1.2875 + g_return_val_if_fail(GST_IS_ADAPTER(adapter), NULL);
1.2876 + g_return_val_if_fail(nbytes > 0, NULL);
1.2877
1.2878 - GST_LOG_OBJECT (adapter, "taking buffer of %u bytes", nbytes);
1.2879 + GST_LOG_OBJECT(adapter, "taking buffer of %u bytes", nbytes);
1.2880
1.2881 - /* we don't have enough data, return NULL. This is unlikely
1.2882 - * as one usually does an _available() first instead of peeking a
1.2883 - * random size. */
1.2884 - if (G_UNLIKELY (nbytes > adapter->size))
1.2885 - return NULL;
1.2886 + /* we don't have enough data, return NULL. This is unlikely
1.2887 + * as one usually does an _available() first instead of peeking a
1.2888 + * random size. */
1.2889 + if (G_UNLIKELY(nbytes > adapter->size))
1.2890 + return NULL;
1.2891
1.2892 - /* our head buffer has enough data left, return it */
1.2893 + /* our head buffer has enough data left, return it */
1.2894 cur = adapter->buflist->data;
1.2895 - if (GST_BUFFER_SIZE (cur) >= nbytes + adapter->skip) {
1.2896 - GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer",
1.2897 - nbytes);
1.2898 - buffer = gst_buffer_create_sub (cur, adapter->skip, nbytes);
1.2899 + if (GST_BUFFER_SIZE(cur) >= nbytes + adapter->skip)
1.2900 + {
1.2901 + GST_LOG_OBJECT(adapter, "providing buffer of %d bytes via sub-buffer",
1.2902 + nbytes);
1.2903 + buffer = gst_buffer_create_sub(cur, adapter->skip, nbytes);
1.2904
1.2905 - gst_adapter_flush (adapter, nbytes);
1.2906 + gst_adapter_flush(adapter, nbytes);
1.2907
1.2908 - return buffer;
1.2909 - }
1.2910 + return buffer;
1.2911 + }
1.2912
1.2913 - data = gst_adapter_take (adapter, nbytes);
1.2914 + data = gst_adapter_take(adapter, nbytes);
1.2915 if (data == NULL)
1.2916 - return NULL;
1.2917 + return NULL;
1.2918
1.2919 - buffer = gst_buffer_new ();
1.2920 - GST_BUFFER_DATA (buffer) = data;
1.2921 - GST_BUFFER_MALLOCDATA (buffer) = data;
1.2922 - GST_BUFFER_SIZE (buffer) = nbytes;
1.2923 + buffer = gst_buffer_new();
1.2924 + GST_BUFFER_DATA(buffer) = data;
1.2925 + GST_BUFFER_MALLOCDATA(buffer) = data;
1.2926 + GST_BUFFER_SIZE(buffer) = nbytes;
1.2927
1.2928 return buffer;
1.2929 }
1.2930 #endif
1.2931
1.2932 static void
1.2933 -gst_nuv_typefind (GstTypeFind * tf, gpointer unused)
1.2934 +gst_nuv_typefind(GstTypeFind * tf, gpointer unused)
1.2935 {
1.2936 - guint8 *data = gst_type_find_peek (tf, 0, 11);
1.2937 + guint8 *data = gst_type_find_peek(tf, 0, 11);
1.2938
1.2939 - if (data) {
1.2940 - if (memcmp (data, "MythTVVideo", 11) == 0
1.2941 - || memcmp (data, "NuppelVideo", 11) == 0) {
1.2942 - gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
1.2943 - gst_caps_new_simple ("video/x-nuv", NULL));
1.2944 - }
1.2945 - }
1.2946 + if (data)
1.2947 + {
1.2948 + if (memcmp(data, "MythTVVideo", 11) == 0
1.2949 + || memcmp(data, "NuppelVideo", 11) == 0)
1.2950 + {
1.2951 + gst_type_find_suggest(tf, GST_TYPE_FIND_MAXIMUM,
1.2952 + gst_caps_new_simple("video/x-nuv", NULL));
1.2953 + }
1.2954 + }
1.2955 }
1.2956
1.2957 static gboolean
1.2958 -plugin_init (GstPlugin * plugin)
1.2959 +plugin_init(GstPlugin * plugin)
1.2960 {
1.2961 - static gchar *exts[] = { "nuv", NULL };
1.2962 + static gchar *exts[] = { "nuv", NULL };
1.2963 #ifdef ENABLE_NLS
1.2964 - setlocale (LC_ALL, "");
1.2965 - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1.2966 + setlocale(LC_ALL, "");
1.2967 + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
1.2968 #endif /* ENABLE_NLS */
1.2969
1.2970 - if (!gst_element_register (plugin, "nuvdemux", GST_RANK_SECONDARY,
1.2971 - GST_TYPE_NUV_DEMUX)) {
1.2972 - return FALSE;
1.2973 - }
1.2974 + if (!gst_element_register(plugin, "nuvdemux", GST_RANK_SECONDARY,
1.2975 + GST_TYPE_NUV_DEMUX))
1.2976 + {
1.2977 + return FALSE;
1.2978 + }
1.2979
1.2980 - if (!gst_type_find_register (plugin, "video/x-nuv", GST_RANK_SECONDARY,
1.2981 - gst_nuv_typefind,
1.2982 - exts,
1.2983 - gst_caps_new_simple ("video/x-nuv", NULL), NULL, NULL)) {
1.2984 - GST_WARNING ("can't register typefind");
1.2985 - return FALSE;
1.2986 - }
1.2987 + if (!gst_type_find_register(plugin, "video/x-nuv", GST_RANK_SECONDARY,
1.2988 + gst_nuv_typefind,
1.2989 + exts,
1.2990 + gst_caps_new_simple("video/x-nuv", NULL), NULL,
1.2991 + NULL))
1.2992 + {
1.2993 + GST_WARNING("can't register typefind");
1.2994 + return FALSE;
1.2995 + }
1.2996
1.2997 return TRUE;
1.2998 }
1.2999
1.3000 -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1.3001 - GST_VERSION_MINOR,
1.3002 - "nuvdemux",
1.3003 - "Demuxes and muxes audio and video",
1.3004 - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
1.3005 -
1.3006 +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1.3007 + GST_VERSION_MINOR,
1.3008 + "nuvdemux",
1.3009 + "Demuxes and muxes audio and video",
1.3010 + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
1.3011 + GST_PACKAGE_ORIGIN)