changeset 797:f5a231a9a2f1 libavformat

support changing in bitstream global headers into extradata style and back
author michael
date Mon, 27 Jun 2005 00:04:03 +0000
parents 75246147b635
children b54823a20627
files avformat.h utils.c
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/avformat.h	Sun Jun 26 20:26:47 2005 +0000
+++ b/avformat.h	Mon Jun 27 00:04:03 2005 +0000
@@ -42,6 +42,7 @@
 #define PKT_FLAG_KEY   0x0001
 
 void av_destruct_packet_nofree(AVPacket *pkt);
+void av_destruct_packet(AVPacket *pkt);
 
 /* initialize optional fields of a packet */
 static inline void av_init_packet(AVPacket *pkt)
--- a/utils.c	Sun Jun 26 20:26:47 2005 +0000
+++ b/utils.c	Mon Jun 27 00:04:03 2005 +0000
@@ -165,7 +165,7 @@
 /**
  * Default packet destructor 
  */
-static void av_destruct_packet(AVPacket *pkt)
+void av_destruct_packet(AVPacket *pkt)
 {
     av_free(pkt->data);
     pkt->data = NULL; pkt->size = 0;
@@ -834,7 +834,7 @@
         /* select current input stream component */
         st = s->cur_st;
         if (st) {
-            if (!st->parser) {
+            if (!st->need_parsing || !st->parser) {
                 /* no parsing needed: we just output the packet as is */
                 /* raw data support */
                 *pkt = s->cur_pkt;
@@ -876,7 +876,7 @@
                 /* return the last frames, if any */
                 for(i = 0; i < s->nb_streams; i++) {
                     st = s->streams[i];
-                    if (st->parser) {
+                    if (st->parser && st->need_parsing) {
                         av_parser_parse(st->parser, &st->codec, 
                                         &pkt->data, &pkt->size, 
                                         NULL, 0, 
@@ -1742,6 +1742,10 @@
             if(!st->codec.time_base.num)
                 st->codec.time_base= st->time_base;
         }
+        //only for the split stuff
+        if (!st->parser) {
+            st->parser = av_parser_init(st->codec.codec_id);
+        }
     }
 
     for(i=0;i<MAX_STREAMS;i++){
@@ -1762,6 +1766,8 @@
             if(   st->codec.time_base.den >= 1000LL*st->codec.time_base.num
                && duration_count[i]<20 && st->codec.codec_type == CODEC_TYPE_VIDEO)
                 break;
+            if(st->parser && st->parser->parser->split && !st->codec.extradata)
+                break;
         }
         if (i == ic->nb_streams) {
             /* NOTE: if the format has no header, then we need to read
@@ -1841,6 +1847,15 @@
             }
             last_dts[pkt->stream_index]= pkt->dts;
         }
+        if(st->parser && st->parser->parser->split && !st->codec.extradata){
+            int i= st->parser->parser->split(&st->codec, pkt->data, pkt->size);
+            if(i){
+                st->codec.extradata_size= i;
+                st->codec.extradata= av_malloc(st->codec.extradata_size);
+                memcpy(st->codec.extradata, pkt->data, st->codec.extradata_size);
+            }
+        }
+        
         /* if still no information, we try to open the codec and to
            decompress the frame. We try to avoid that in most cases as
            it takes longer and uses more memory. For MPEG4, we need to