[FFmpeg-soc] [soc]: r2392 - in dvbmuxer: mpegenc.c mpegpes.h mpegpesenc.c mpegtsenc.c

bcoudurier subversion at mplayerhq.hu
Thu Jun 5 20:37:24 CEST 2008


Author: bcoudurier
Date: Thu Jun  5 20:37:23 2008
New Revision: 2392

Log:
factorize ff_pes_output_packet

Modified:
   dvbmuxer/mpegenc.c
   dvbmuxer/mpegpes.h
   dvbmuxer/mpegpesenc.c
   dvbmuxer/mpegtsenc.c

Modified: dvbmuxer/mpegenc.c
==============================================================================
--- dvbmuxer/mpegenc.c	(original)
+++ dvbmuxer/mpegenc.c	Thu Jun  5 20:37:23 2008
@@ -799,38 +799,16 @@ static int64_t get_vcd_scr(AVFormatConte
 
 static int output_packet(AVFormatContext *ctx, int flush){
     MpegMuxContext *s = ctx->priv_data;
-    AVStream *st;
     StreamInfo *stream;
-    int res, es_size, trailer_size;
+    int es_size;
     int best_i= -1;
     int64_t scr= s->last_scr;
-    PacketDesc *timestamp_packet;
-
-    if((res = ff_pes_find_beststream(ctx, s->packet_size, flush,
-                                        &scr, &best_i)) <= 0)
-        return res;
-    assert(best_i >= 0);
 
-    st = ctx->streams[best_i];
-    stream = st->priv_data;
-
-    assert(av_fifo_size(&stream->fifo) > 0);
-
-    timestamp_packet= stream->premux_packet;
-    if(timestamp_packet->unwritten_size == timestamp_packet->size){
-        trailer_size= 0;
-    }else{
-        trailer_size= timestamp_packet->unwritten_size;
-        timestamp_packet= timestamp_packet->next;
-    }
+    if ((es_size = ff_pes_output_packet(ctx, s->packet_size, &scr, &best_i,
+                                        flush, flush_packet)) <= 0)
+        return es_size;
 
-    if(timestamp_packet){
-//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i);
-        es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size);
-    }else{
-        assert(av_fifo_size(&stream->fifo) == trailer_size);
-        es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size);
-    }
+    stream= ctx->streams[best_i]->priv_data;
 
     if (s->is_vcd) {
         /* Write one or more padding sectors, if necessary, to reach
@@ -873,8 +851,6 @@ static int mpeg_mux_write_packet(AVForma
 static int mpeg_mux_end(AVFormatContext *ctx)
 {
     MpegMuxContext *s = ctx->priv_data;
-    StreamInfo *stream;
-    int i;
 
     for(;;){
         int ret= output_packet(ctx, 1);

Modified: dvbmuxer/mpegpes.h
==============================================================================
--- dvbmuxer/mpegpes.h	(original)
+++ dvbmuxer/mpegpes.h	Thu Jun  5 20:37:23 2008
@@ -74,7 +74,7 @@ typedef struct {
 /**
  * Initialization of PES muxer.
  * @param[in] ctx AVFormatContext
- * @return        Negative value on error, zero on success.
+ * @return        Negative value on error, zero on success
  */
 int ff_pes_muxer_init(AVFormatContext *ctx);
 
@@ -87,7 +87,7 @@ void ff_pes_muxer_end(AVFormatContext *c
 /**
  * Write packet into PES FIFO.
  * @param [in] ctx           AVFormatContext
- * @param [in] pkt           Packet to write.
+ * @param [in] pkt           Packet to write
  * @param [in] packet_number Current muxer packet number
  */
 void ff_pes_write_packet(AVFormatContext *ctx, AVPacket *pkt, int packet_number);
@@ -96,15 +96,32 @@ void ff_pes_write_packet(AVFormatContext
  * Find the best stream to mux into the PES stream.
  * @param[in]  ctx         AVFormatContext
  * @param[in]  packet_size PES stream packet size
- * @param[in]  flush       Flush after every single subtitle packet.
+ * @param[in]  flush       Wether flushing remaining data is needed
  * @param[in]  scr         Current clock reference
  * @param[out] scr         Updated clock reference, bumped if needed
  * @param[out] best_i      Index of the stream to be muxed
- * @return                 Negative on error, zero if not found, 1 if found.
+ * @return                 Negative on error, zero if not found, 1 if found
  */
 int ff_pes_find_beststream(AVFormatContext *ctx, int packet_size, int flush, int64_t *scr, int *best_i);
 
 /**
+ * Output PES packet to the output file.
+ * @param[in]  ctx          AVFormatContext
+ * @param[in]  packet_size  PES stream packet size
+ * @param[in]  flush        Wether flushing remaining data is needed
+ * @param[in]  cr           Last clock reference (SCR for PS, PCR for TS)
+ * @param[out] cr           Updated clock reference, bumped if needed
+ * @param[out] best_i       Index of the stream muxed
+ * @param[in]  flush_packet Function to call to actually write packet to file
+ * @return                  Negative on error, zero if no packet output,
+ *                          else Byte size of flushed data
+ */
+int ff_pes_output_packet(AVFormatContext *ctx, int packet_size,
+                         int64_t *cr, int *best_i, int flush,
+                         int (*flush_packet)(AVFormatContext *, int, int64_t,
+                                             int64_t, int64_t, int));
+
+/**
  * Write PES data from PES Stream into supplied buffer.
  * @param [in]  ctx               AVFormatContext
  * @param [in]  stream_index      Stream index to write from
@@ -127,7 +144,7 @@ int ff_pes_write_buf(AVFormatContext *ct
  * Remove decoded packets of each stream.
  * @param[in] ctx  the AVFormatContext
  * @param[in] scr  System Clock Reference of PES stream
- * @return         Negative value on error, 0 on success.
+ * @return         Negative value on error, 0 on success
  */
 int ff_pes_remove_decoded_packets(AVFormatContext *ctx, int64_t scr);
 

Modified: dvbmuxer/mpegpesenc.c
==============================================================================
--- dvbmuxer/mpegpesenc.c	(original)
+++ dvbmuxer/mpegpesenc.c	Thu Jun  5 20:37:23 2008
@@ -420,6 +420,42 @@ void ff_pes_write_packet(AVFormatContext
     av_fifo_generic_write(&stream->fifo, buf, size, NULL);
 }
 
+int ff_pes_output_packet(AVFormatContext *ctx, int packet_size, int64_t *cr,
+                         int *best_i, int flush, int (*flush_packet)())
+{
+    AVStream *st;
+    StreamInfo *stream;
+    int trailer_size, res;
+    PacketDesc *timestamp_packet;
+
+    if((res = ff_pes_find_beststream(ctx, packet_size,
+                                     flush, cr, best_i)) <= 0)
+        return res;
+    assert(*best_i >= 0);
+
+    st = ctx->streams[*best_i];
+    stream = st->priv_data;
+
+    assert(av_fifo_size(&stream->fifo) > 0);
+
+    timestamp_packet= stream->premux_packet;
+    if(timestamp_packet->unwritten_size == timestamp_packet->size){
+        trailer_size= 0;
+    }else{
+        trailer_size= timestamp_packet->unwritten_size;
+        timestamp_packet= timestamp_packet->next;
+    }
+
+    if(timestamp_packet){
+//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f pcr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, pcr/90000.0, best_i);
+        return flush_packet(ctx, *best_i, timestamp_packet->pts, timestamp_packet->dts, *cr, trailer_size);
+    }else{
+        assert(av_fifo_size(&stream->fifo) == trailer_size);
+        return flush_packet(ctx, *best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, *cr, trailer_size);
+    }
+}
+
+
 void ff_pes_muxer_end(AVFormatContext *ctx)
 {
     StreamInfo *stream;

Modified: dvbmuxer/mpegtsenc.c
==============================================================================
--- dvbmuxer/mpegtsenc.c	(original)
+++ dvbmuxer/mpegtsenc.c	Thu Jun  5 20:37:23 2008
@@ -637,39 +637,16 @@ static int flush_packet(AVFormatContext 
 
 static int output_packet(AVFormatContext *ctx, int flush){
     MpegTSWrite *s = ctx->priv_data;
-    AVStream *st;
     StreamInfo *stream;
-    int es_size, trailer_size, res;
+    int es_size;
     int best_i= -1;
-    int64_t pcr = s->last_pcr;
-    PacketDesc *timestamp_packet;
-
-    if((res = ff_pes_find_beststream(ctx, DEFAULT_PES_PAYLOAD_SIZE,
-                                     flush, &pcr, &best_i)) <= 0)
-        return res;
-    assert(best_i >= 0);
-
-    st = ctx->streams[best_i];
-    stream = st->priv_data;
-
-    assert(av_fifo_size(&stream->fifo) > 0);
-
-    timestamp_packet= stream->premux_packet;
-    if(timestamp_packet->unwritten_size == timestamp_packet->size){
-        trailer_size= 0;
-    }else{
-        trailer_size= timestamp_packet->unwritten_size;
-        timestamp_packet= timestamp_packet->next;
-    }
+    int64_t pcr= s->last_pcr;
 
-    if(timestamp_packet){
-//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f pcr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, pcr/90000.0, best_i);
-        es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, pcr, trailer_size);
-    }else{
-        assert(av_fifo_size(&stream->fifo) == trailer_size);
-        es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, pcr, trailer_size);
-    }
+    if ((es_size = ff_pes_output_packet(ctx, DEFAULT_PES_PAYLOAD_SIZE,
+                                        &pcr, &best_i, flush, flush_packet)) <= 0)
+        return es_size;
 
+    stream= ctx->streams[best_i]->priv_data;
     stream->buffer_index += es_size;
     while(stream->premux_packet && stream->premux_packet->unwritten_size <= es_size){
         es_size -= stream->premux_packet->unwritten_size;



More information about the FFmpeg-soc mailing list