Browse code

remove function call from muxer->encoder and cleanly pass global headers

Originally committed as revision 2956 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2004/04/05 00:19:20
Showing 3 changed files
... ...
@@ -7,7 +7,6 @@
7 7
 #include <vorbis/vorbisenc.h>
8 8
 
9 9
 #include "avcodec.h"
10
-#include "oggvorbis.h"
11 10
 
12 11
 //#define OGGVORBIS_FRAME_SIZE 1024
13 12
 #define OGGVORBIS_FRAME_SIZE 64
... ...
@@ -27,7 +26,7 @@ typedef struct OggVorbisContext {
27 27
 } OggVorbisContext ;
28 28
 
29 29
 
30
-int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
30
+static int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
31 31
 
32 32
 #ifdef OGGVORBIS_VBR_BY_ESTIMATE
33 33
     /* variable bitrate by estimate */
... ...
@@ -44,9 +43,10 @@ int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
44 44
 #endif
45 45
 }
46 46
 
47
-
48 47
 static int oggvorbis_encode_init(AVCodecContext *avccontext) {
49 48
     OggVorbisContext *context = avccontext->priv_data ;
49
+    ogg_packet header, header_comm, header_code;
50
+    uint8_t *p;
50 51
 
51 52
     vorbis_info_init(&context->vi) ;
52 53
     if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
... ...
@@ -56,6 +56,34 @@ static int oggvorbis_encode_init(AVCodecContext *avccontext) {
56 56
     vorbis_analysis_init(&context->vd, &context->vi) ;
57 57
     vorbis_block_init(&context->vd, &context->vb) ;
58 58
 
59
+    vorbis_comment_init(&context->vc);
60
+    vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ;
61
+
62
+    vorbis_analysis_headerout(&context->vd, &context->vc, &header,
63
+                                &header_comm, &header_code);
64
+    
65
+    avccontext->extradata_size= 3*2 + header.bytes + header_comm.bytes +  header_code.bytes;
66
+    p= avccontext->extradata= av_mallocz(avccontext->extradata_size);
67
+    
68
+    *(p++) = header.bytes>>8;
69
+    *(p++) = header.bytes&0xFF;
70
+    memcpy(p, header.packet, header.bytes);
71
+    p += header.bytes;
72
+    
73
+    *(p++) = header_comm.bytes>>8;
74
+    *(p++) = header_comm.bytes&0xFF;
75
+    memcpy(p, header_comm.packet, header_comm.bytes);
76
+    p += header_comm.bytes;
77
+    
78
+    *(p++) = header_code.bytes>>8;
79
+    *(p++) = header_code.bytes&0xFF;
80
+    memcpy(p, header_code.packet, header_code.bytes);
81
+                                
82
+/*    vorbis_block_clear(&context->vb);
83
+    vorbis_dsp_clear(&context->vd);
84
+    vorbis_info_clear(&context->vi);*/
85
+    vorbis_comment_clear(&context->vc);
86
+       
59 87
     avccontext->frame_size = OGGVORBIS_FRAME_SIZE ;
60 88
  
61 89
     avccontext->coded_frame= avcodec_alloc_frame();
... ...
@@ -103,7 +131,7 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext,
103 103
     }
104 104
 
105 105
     if(context->buffer_index){
106
-        ogg_packet *op2= context->buffer;
106
+        ogg_packet *op2= (ogg_packet*)context->buffer;
107 107
         op2->packet = context->buffer + sizeof(ogg_packet);
108 108
         l=  op2->bytes;
109 109
         
... ...
@@ -143,6 +171,7 @@ static int oggvorbis_encode_close(AVCodecContext *avccontext) {
143 143
     vorbis_info_clear(&context->vi);
144 144
 
145 145
     av_freep(&avccontext->coded_frame);
146
+    av_freep(&avccontext->extradata);
146 147
   
147 148
     return 0 ;
148 149
 }
149 150
deleted file mode 100644
... ...
@@ -1,15 +0,0 @@
1
-/**
2
- * @file oggvorbis.h
3
- * oggvorbis.
4
- */
5
-
6
-#ifndef AVCODEC_OGGVORBIS_H
7
-#define AVCODEC_OGGVORBIS_H
8
-
9
-#include <vorbis/vorbisenc.h>
10
-
11
-#include "avcodec.h"
12
-
13
-int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) ;
14
-
15
-#endif
... ...
@@ -9,10 +9,8 @@
9 9
 #include <stdio.h>
10 10
 
11 11
 #include <ogg/ogg.h>
12
-#include <vorbis/vorbisenc.h>
13 12
 
14 13
 #include "avformat.h"
15
-#include "oggvorbis.h"
16 14
 
17 15
 #undef NDEBUG
18 16
 #include <assert.h>
... ...
@@ -35,52 +33,28 @@ typedef struct OggContext {
35 35
 static int ogg_write_header(AVFormatContext *avfcontext) 
36 36
 {
37 37
     OggContext *context = avfcontext->priv_data;
38
-    AVCodecContext *avccontext ;
39
-    vorbis_info vi ;
40
-    vorbis_dsp_state vd ;
41
-    vorbis_comment vc ;
42
-    vorbis_block vb ;
43
-    ogg_packet header, header_comm, header_code ; 
44
-    int n ;
38
+    ogg_packet *op= &context->op;    
39
+    int n, i;
45 40
 
46 41
     av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE);
47 42
 
48 43
     ogg_stream_init(&context->os, 31415);
49 44
     
50 45
     for(n = 0 ; n < avfcontext->nb_streams ; n++) {
51
-	avccontext = &avfcontext->streams[n]->codec ;
46
+        AVCodecContext *codec = &avfcontext->streams[n]->codec;
47
+        uint8_t *p= codec->extradata;
48
+        
49
+        for(i=0; i < codec->extradata_size; i+= op->bytes){
50
+            op->bytes = p[i++]<<8;
51
+            op->bytes+= p[i++];
52 52
 
53
-	/* begin vorbis specific code */
54
-		
55
-	vorbis_info_init(&vi) ;
53
+            op->packet= &p[i];
54
+            op->b_o_s= op->packetno==0;
56 55
 
57
-	/* code copied from libavcodec/oggvorbis.c */
56
+            ogg_stream_packetin(&context->os, op);
58 57
 
59
-	if(oggvorbis_init_encoder(&vi, avccontext) < 0) {
60
-	    fprintf(stderr, "ogg_write_header: init_encoder failed") ;
61
-	    return -1 ;
62
-	}
63
-
64
-	vorbis_analysis_init(&vd, &vi) ;
65
-	vorbis_block_init(&vd, &vb) ;
66
-	
67
-	vorbis_comment_init(&vc) ;
68
-	vorbis_comment_add_tag(&vc, "encoder", LIBAVFORMAT_IDENT) ;
69
-	if(*avfcontext->title)
70
-	    vorbis_comment_add_tag(&vc, "title", avfcontext->title) ;
71
-
72
-	vorbis_analysis_headerout(&vd, &vc, &header,
73
-				  &header_comm, &header_code) ;
74
-	ogg_stream_packetin(&context->os, &header) ;
75
-	ogg_stream_packetin(&context->os, &header_comm) ;
76
-	ogg_stream_packetin(&context->os, &header_code) ;  
77
-	
78
-	vorbis_block_clear(&vb) ;
79
-	vorbis_dsp_clear(&vd) ;
80
-	vorbis_info_clear(&vi) ;
81
-	vorbis_comment_clear(&vc) ;
82
-	
83
-	/* end of vorbis specific code */
58
+            op->packetno++; //FIXME multiple streams
59
+        }
84 60
 
85 61
 	context->header_handled = 0 ;
86 62
     }
... ...
@@ -88,7 +62,6 @@ static int ogg_write_header(AVFormatContext *avfcontext)
88 88
     return 0 ;
89 89
 }
90 90
 
91
-
92 91
 static int ogg_write_packet(AVFormatContext *avfcontext,
93 92
 			    int stream_index,
94 93
 			    const uint8_t *buf, int size, int64_t pts)