aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2004-04-04 15:19:20 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-04-04 15:19:20 +0000
commitbbb77e7c2eceaf4924783ff3fdb145613c499bcb (patch)
tree9129e1e0faf5a1532b9ea456a4633fc77ad2268e
parent6d8f985ecfb1cab04dc114307091282db6f16933 (diff)
downloadffmpeg-bbb77e7c2eceaf4924783ff3fdb145613c499bcb.tar.gz
remove function call from muxer->encoder and cleanly pass global headers
Originally committed as revision 2956 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/oggvorbis.c37
-rw-r--r--libavcodec/oggvorbis.h15
-rw-r--r--libavformat/ogg.c53
3 files changed, 46 insertions, 59 deletions
diff --git a/libavcodec/oggvorbis.c b/libavcodec/oggvorbis.c
index 104895ae79..38145cc1b1 100644
--- a/libavcodec/oggvorbis.c
+++ b/libavcodec/oggvorbis.c
@@ -7,7 +7,6 @@
#include <vorbis/vorbisenc.h>
#include "avcodec.h"
-#include "oggvorbis.h"
//#define OGGVORBIS_FRAME_SIZE 1024
#define OGGVORBIS_FRAME_SIZE 64
@@ -27,7 +26,7 @@ typedef struct OggVorbisContext {
} OggVorbisContext ;
-int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
+static int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
#ifdef OGGVORBIS_VBR_BY_ESTIMATE
/* variable bitrate by estimate */
@@ -44,9 +43,10 @@ int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
#endif
}
-
static int oggvorbis_encode_init(AVCodecContext *avccontext) {
OggVorbisContext *context = avccontext->priv_data ;
+ ogg_packet header, header_comm, header_code;
+ uint8_t *p;
vorbis_info_init(&context->vi) ;
if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
@@ -56,6 +56,34 @@ static int oggvorbis_encode_init(AVCodecContext *avccontext) {
vorbis_analysis_init(&context->vd, &context->vi) ;
vorbis_block_init(&context->vd, &context->vb) ;
+ vorbis_comment_init(&context->vc);
+ vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ;
+
+ vorbis_analysis_headerout(&context->vd, &context->vc, &header,
+ &header_comm, &header_code);
+
+ avccontext->extradata_size= 3*2 + header.bytes + header_comm.bytes + header_code.bytes;
+ p= avccontext->extradata= av_mallocz(avccontext->extradata_size);
+
+ *(p++) = header.bytes>>8;
+ *(p++) = header.bytes&0xFF;
+ memcpy(p, header.packet, header.bytes);
+ p += header.bytes;
+
+ *(p++) = header_comm.bytes>>8;
+ *(p++) = header_comm.bytes&0xFF;
+ memcpy(p, header_comm.packet, header_comm.bytes);
+ p += header_comm.bytes;
+
+ *(p++) = header_code.bytes>>8;
+ *(p++) = header_code.bytes&0xFF;
+ memcpy(p, header_code.packet, header_code.bytes);
+
+/* vorbis_block_clear(&context->vb);
+ vorbis_dsp_clear(&context->vd);
+ vorbis_info_clear(&context->vi);*/
+ vorbis_comment_clear(&context->vc);
+
avccontext->frame_size = OGGVORBIS_FRAME_SIZE ;
avccontext->coded_frame= avcodec_alloc_frame();
@@ -103,7 +131,7 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext,
}
if(context->buffer_index){
- ogg_packet *op2= context->buffer;
+ ogg_packet *op2= (ogg_packet*)context->buffer;
op2->packet = context->buffer + sizeof(ogg_packet);
l= op2->bytes;
@@ -143,6 +171,7 @@ static int oggvorbis_encode_close(AVCodecContext *avccontext) {
vorbis_info_clear(&context->vi);
av_freep(&avccontext->coded_frame);
+ av_freep(&avccontext->extradata);
return 0 ;
}
diff --git a/libavcodec/oggvorbis.h b/libavcodec/oggvorbis.h
deleted file mode 100644
index fd431dc64c..0000000000
--- a/libavcodec/oggvorbis.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * @file oggvorbis.h
- * oggvorbis.
- */
-
-#ifndef AVCODEC_OGGVORBIS_H
-#define AVCODEC_OGGVORBIS_H
-
-#include <vorbis/vorbisenc.h>
-
-#include "avcodec.h"
-
-int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) ;
-
-#endif
diff --git a/libavformat/ogg.c b/libavformat/ogg.c
index 3c8b1e2b9c..43d111d5b5 100644
--- a/libavformat/ogg.c
+++ b/libavformat/ogg.c
@@ -9,10 +9,8 @@
#include <stdio.h>
#include <ogg/ogg.h>
-#include <vorbis/vorbisenc.h>
#include "avformat.h"
-#include "oggvorbis.h"
#undef NDEBUG
#include <assert.h>
@@ -35,52 +33,28 @@ typedef struct OggContext {
static int ogg_write_header(AVFormatContext *avfcontext)
{
OggContext *context = avfcontext->priv_data;
- AVCodecContext *avccontext ;
- vorbis_info vi ;
- vorbis_dsp_state vd ;
- vorbis_comment vc ;
- vorbis_block vb ;
- ogg_packet header, header_comm, header_code ;
- int n ;
+ ogg_packet *op= &context->op;
+ int n, i;
av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE);
ogg_stream_init(&context->os, 31415);
for(n = 0 ; n < avfcontext->nb_streams ; n++) {
- avccontext = &avfcontext->streams[n]->codec ;
+ AVCodecContext *codec = &avfcontext->streams[n]->codec;
+ uint8_t *p= codec->extradata;
+
+ for(i=0; i < codec->extradata_size; i+= op->bytes){
+ op->bytes = p[i++]<<8;
+ op->bytes+= p[i++];
- /* begin vorbis specific code */
-
- vorbis_info_init(&vi) ;
+ op->packet= &p[i];
+ op->b_o_s= op->packetno==0;
- /* code copied from libavcodec/oggvorbis.c */
+ ogg_stream_packetin(&context->os, op);
- if(oggvorbis_init_encoder(&vi, avccontext) < 0) {
- fprintf(stderr, "ogg_write_header: init_encoder failed") ;
- return -1 ;
- }
-
- vorbis_analysis_init(&vd, &vi) ;
- vorbis_block_init(&vd, &vb) ;
-
- vorbis_comment_init(&vc) ;
- vorbis_comment_add_tag(&vc, "encoder", LIBAVFORMAT_IDENT) ;
- if(*avfcontext->title)
- vorbis_comment_add_tag(&vc, "title", avfcontext->title) ;
-
- vorbis_analysis_headerout(&vd, &vc, &header,
- &header_comm, &header_code) ;
- ogg_stream_packetin(&context->os, &header) ;
- ogg_stream_packetin(&context->os, &header_comm) ;
- ogg_stream_packetin(&context->os, &header_code) ;
-
- vorbis_block_clear(&vb) ;
- vorbis_dsp_clear(&vd) ;
- vorbis_info_clear(&vi) ;
- vorbis_comment_clear(&vc) ;
-
- /* end of vorbis specific code */
+ op->packetno++; //FIXME multiple streams
+ }
context->header_handled = 0 ;
}
@@ -88,7 +62,6 @@ static int ogg_write_header(AVFormatContext *avfcontext)
return 0 ;
}
-
static int ogg_write_packet(AVFormatContext *avfcontext,
int stream_index,
const uint8_t *buf, int size, int64_t pts)