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