gst-gmyth/nuvdemux/gstnuvdemux.c
branchtrunk
changeset 715 e01c60057f07
parent 713 e8fe96f87916
child 716 1ee5df4c9ccd
     1.1 --- a/gst-gmyth/nuvdemux/gstnuvdemux.c	Fri May 25 15:56:10 2007 +0100
     1.2 +++ b/gst-gmyth/nuvdemux/gstnuvdemux.c	Fri May 25 18:25:50 2007 +0100
     1.3 @@ -203,7 +203,9 @@
     1.4    GstFlowReturn     last_video_return;
     1.5    GstFlowReturn     last_audio_return;
     1.6    gboolean          more_data;
     1.7 -  gboolean	    eos;
     1.8 +  gboolean	    	eos;
     1.9 +  gboolean 			new_file;
    1.10 +  guint 			segment;
    1.11  
    1.12    /* NUV decoding state */
    1.13    GstNuvDemuxState  state;
    1.14 @@ -267,7 +269,7 @@
    1.15  static gboolean gst_nuv_demux_sink_activate_push (GstPad * pad,
    1.16      gboolean active);
    1.17  static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad);
    1.18 -//static gboolean gst_nuv_demux_sink_event    (GstPad *pad, GstEvent *event);
    1.19 +static gboolean gst_nuv_demux_sink_event    (GstPad *pad, GstEvent *event);
    1.20  static gboolean gst_nuv_demux_srcpad_event  (GstPad * pad, GstEvent * event);
    1.21  static frame_index_data * gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos, 
    1.22    gint64 segment_stop, GstFormat format);
    1.23 @@ -387,10 +389,9 @@
    1.24        gst_nuv_demux_sink_activate_push);
    1.25    gst_pad_set_chain_function (nuv->priv->sinkpad,
    1.26        GST_DEBUG_FUNCPTR (gst_nuv_demux_chain));
    1.27 -/*
    1.28    gst_pad_set_event_function (nuv->priv->sinkpad,
    1.29 -      gst_nuv_demux_sink_event);
    1.30 -*/
    1.31 +      GST_DEBUG_FUNCPTR (gst_nuv_demux_sink_event));
    1.32 +
    1.33  
    1.34    gst_element_add_pad (GST_ELEMENT (nuv), nuv->priv->sinkpad);
    1.35  
    1.36 @@ -433,27 +434,29 @@
    1.37        goto done;
    1.38    }
    1.39  
    1.40 -  memcpy (h->id, buffer->data, 12);
    1.41 -  memcpy (h->version, buffer->data + 12, 5);
    1.42 -  h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
    1.43 -  h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
    1.44 -  h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
    1.45 -  h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
    1.46 -  h->i_mode = GPOINTER_TO_INT (buffer->data[36]);
    1.47 -  h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
    1.48 -  h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
    1.49 -  /* get the num and denom values from fps */
    1.50 -  double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd);
    1.51 -  h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
    1.52 -  h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
    1.53 -  h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
    1.54 -  h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
    1.55 +  if (h != NULL) {
    1.56 +  	memcpy (h->id, buffer->data, 12);
    1.57 +	memcpy (h->version, buffer->data + 12, 5);
    1.58 +  	h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
    1.59 +  	h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
    1.60 +  	h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
    1.61 +  	h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
    1.62 +  	h->i_mode = GPOINTER_TO_INT (buffer->data[36]);
    1.63 +  	h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
    1.64 +  	h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
    1.65 +  	/* get the num and denom values from fps */
    1.66 +  	double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd);
    1.67 +  	h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
    1.68 +  	h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
    1.69 +  	h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
    1.70 +  	h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
    1.71  
    1.72 -  GST_DEBUG_OBJECT (nuv,
    1.73 -      "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
    1.74 -      h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
    1.75 -      h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
    1.76 -      h->i_keyframe_distance);
    1.77 +  	GST_DEBUG_OBJECT (nuv,
    1.78 +    	"nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
    1.79 +      	h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
    1.80 +      	h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
    1.81 +      	h->i_keyframe_distance);
    1.82 +  }
    1.83  
    1.84  done:
    1.85    if (buffer != NULL) {
    1.86 @@ -468,7 +471,11 @@
    1.87  {
    1.88    GstFlowReturn res;
    1.89  
    1.90 -  res = gst_nuv_demux_header_load (nuv, &nuv->priv->h);
    1.91 +  if (nuv->priv->new_file) 
    1.92 +	  res = gst_nuv_demux_header_load (nuv, NULL);
    1.93 +  else
    1.94 +	  res = gst_nuv_demux_header_load (nuv, &nuv->priv->h);
    1.95 +
    1.96    if (res == GST_FLOW_OK)
    1.97      nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
    1.98    return res;
    1.99 @@ -516,7 +523,12 @@
   1.100        goto done;
   1.101    }
   1.102  
   1.103 +  if (h == NULL)
   1.104 +	goto done;
   1.105 +		  
   1.106    data = buf->data;
   1.107 +<<<<<<< .mine
   1.108 +=======
   1.109    /* verifies if it is a MythTV file header */
   1.110    if ( ( data[0] == 'M' || data[0] == 'N') && data[6] == 'V' )  {
   1.111  	  nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
   1.112 @@ -525,6 +537,7 @@
   1.113    /* it is not a NUV file header, so now can move the 12 bytes */
   1.114    res = gst_nuv_demux_move_bytes (nuv, 12);
   1.115  
   1.116 +>>>>>>> .r719
   1.117    h->i_type = GPOINTER_TO_INT (data[0]);
   1.118    h->i_compression = GPOINTER_TO_INT (data[1]);
   1.119    h->i_keyframe = GPOINTER_TO_INT (data[2]);
   1.120 @@ -560,6 +573,9 @@
   1.121        goto done;
   1.122    }
   1.123  
   1.124 +  if (h == NULL)
   1.125 +    goto done;
   1.126 +
   1.127    data = buff->data;
   1.128    h->i_version = GST_READ_UINT32_LE (&data[0]);
   1.129    h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
   1.130 @@ -957,8 +973,15 @@
   1.131    GstFlowReturn ret = GST_FLOW_OK;
   1.132  
   1.133    /* ffmpeg extra data */
   1.134 -  ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE,
   1.135 +  if (nuv->priv->new_file) {
   1.136 +	GstBuffer *buf;
   1.137 +	ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, &buf);
   1.138 +	gst_buffer_unref (buf);
   1.139 +  } else {
   1.140 +    ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE,
   1.141        &nuv->priv->mpeg_buffer);
   1.142 +  }
   1.143 +
   1.144    if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) {
   1.145      return ret;
   1.146    }
   1.147 @@ -976,7 +999,11 @@
   1.148    /* Load 'D' */
   1.149    nuv_frame_header h;
   1.150  
   1.151 -  ret = gst_nuv_demux_frame_header_load (nuv, &h);
   1.152 +  if (nuv->priv->new_file) 
   1.153 +	  ret = gst_nuv_demux_frame_header_load (nuv, NULL);
   1.154 +  else		  
   1.155 +	  ret = gst_nuv_demux_frame_header_load (nuv, &h);
   1.156 +
   1.157    if (ret != GST_FLOW_OK)
   1.158      return ret;
   1.159  
   1.160 @@ -1004,11 +1031,15 @@
   1.161  {
   1.162    GstFlowReturn ret = GST_FLOW_OK;
   1.163  
   1.164 -  ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh);
   1.165 -  if (ret != GST_FLOW_OK)
   1.166 -    return ret;
   1.167 +  if (nuv->priv->new_file)
   1.168 +	  ret = gst_nuv_demux_extended_header_load (nuv, NULL);
   1.169 +  else { 
   1.170 +	  ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh);
   1.171 +	  if (ret != GST_FLOW_OK)
   1.172 +    	return ret;
   1.173 +	  gst_nuv_demux_create_pads (nuv);
   1.174 +  }
   1.175  
   1.176 -  gst_nuv_demux_create_pads (nuv);
   1.177    nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE;
   1.178    return ret;
   1.179  }
   1.180 @@ -1133,7 +1164,7 @@
   1.181        break;
   1.182  
   1.183      case GST_NUV_DEMUX_INDEX_CREATE:
   1.184 -      if (nuv->priv->mode == NUV_PULL_MODE) {
   1.185 +      if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file)) {
   1.186          gst_nuv_demux_create_seek_index (nuv);
   1.187        }
   1.188  
   1.189 @@ -1527,6 +1558,54 @@
   1.190    return res;
   1.191  }
   1.192  
   1.193 +static gboolean
   1.194 +gst_nuv_demux_sink_event (GstPad * pad, GstEvent * event)
   1.195 +{
   1.196 +	gboolean res = FALSE;
   1.197 +	GstNuvDemux *nuv;
   1.198 +
   1.199 +	nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
   1.200 +	
   1.201 +	switch  (GST_EVENT_TYPE (event)) {
   1.202 +		case GST_EVENT_NEWSEGMENT:
   1.203 +		{
   1.204 +			gboolean update;
   1.205 +			gdouble rate;
   1.206 +			GstFormat format;
   1.207 +			gint64 start;
   1.208 +			gint64 stop;
   1.209 +			gint64 position;
   1.210 +
   1.211 +			gst_event_parse_new_segment (event, &update, &rate, &format, &start, &stop, &position);				
   1.212 +			if ((format == GST_FORMAT_BYTES) && (start == 0)) {
   1.213 +				g_debug ("NEW SEGMENT 0");					
   1.214 +				if (nuv->priv->segment > 0) {
   1.215 +					nuv->priv->new_file = TRUE;					
   1.216 +					nuv->priv->state = GST_NUV_DEMUX_START;
   1.217 +					nuv->priv->offset = 0;
   1.218 +				}
   1.219 +				nuv->priv->segment++;					
   1.220 +
   1.221 +				/*
   1.222 +				newsegment_event = gst_event_new_new_segment (FALSE, rate,
   1.223 +				  GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
   1.224 +
   1.225 +    			gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
   1.226 +    			gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
   1.227 +  				gst_event_unref (newsegment_event);
   1.228 +				*/
   1.229 +				res = gst_pad_event_default(pad, event);
   1.230 +			}
   1.231 +			break;
   1.232 +		}
   1.233 +		default:
   1.234 +			res = gst_pad_event_default (pad, event);
   1.235 +			break;
   1.236 +	}	
   1.237 +
   1.238 +	return res;
   1.239 +}
   1.240 +
   1.241  static GstFlowReturn
   1.242  gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
   1.243  {
   1.244 @@ -1577,6 +1656,7 @@
   1.245    nuv->priv->header_lengh = 0;
   1.246    nuv->priv->segment_stop = GST_CLOCK_TIME_NONE;
   1.247    nuv->priv->segment_start = GST_CLOCK_TIME_NONE;
   1.248 +  nuv->priv->new_file = FALSE;
   1.249  
   1.250    //clear index list
   1.251    g_slist_foreach (nuv->priv->index, gst_nuv_demux_index_free, NULL);
   1.252 @@ -1732,6 +1812,6 @@
   1.253  GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
   1.254      GST_VERSION_MINOR,
   1.255      "nuvdemux",
   1.256 -    "Demuxes and muxes audio and video",
   1.257 +    			"Demuxes and muxes audio and video",
   1.258       plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
   1.259