Mercurial > libavformat.hg
comparison ogg.c @ 407:b9d16c18ee18 libavformat
remove function call from muxer->encoder and cleanly pass global headers
author | michael |
---|---|
date | Sun, 04 Apr 2004 15:19:20 +0000 |
parents | ea22a438ca79 |
children | 237eeeb50fb8 |
comparison
equal
deleted
inserted
replaced
406:ea22a438ca79 | 407:b9d16c18ee18 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 | 10 |
11 #include <ogg/ogg.h> | 11 #include <ogg/ogg.h> |
12 #include <vorbis/vorbisenc.h> | |
13 | 12 |
14 #include "avformat.h" | 13 #include "avformat.h" |
15 #include "oggvorbis.h" | |
16 | 14 |
17 #undef NDEBUG | 15 #undef NDEBUG |
18 #include <assert.h> | 16 #include <assert.h> |
19 | 17 |
20 #define DECODER_BUFFER_SIZE 4096 | 18 #define DECODER_BUFFER_SIZE 4096 |
33 | 31 |
34 #ifdef CONFIG_ENCODERS | 32 #ifdef CONFIG_ENCODERS |
35 static int ogg_write_header(AVFormatContext *avfcontext) | 33 static int ogg_write_header(AVFormatContext *avfcontext) |
36 { | 34 { |
37 OggContext *context = avfcontext->priv_data; | 35 OggContext *context = avfcontext->priv_data; |
38 AVCodecContext *avccontext ; | 36 ogg_packet *op= &context->op; |
39 vorbis_info vi ; | 37 int n, i; |
40 vorbis_dsp_state vd ; | |
41 vorbis_comment vc ; | |
42 vorbis_block vb ; | |
43 ogg_packet header, header_comm, header_code ; | |
44 int n ; | |
45 | 38 |
46 av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE); | 39 av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE); |
47 | 40 |
48 ogg_stream_init(&context->os, 31415); | 41 ogg_stream_init(&context->os, 31415); |
49 | 42 |
50 for(n = 0 ; n < avfcontext->nb_streams ; n++) { | 43 for(n = 0 ; n < avfcontext->nb_streams ; n++) { |
51 avccontext = &avfcontext->streams[n]->codec ; | 44 AVCodecContext *codec = &avfcontext->streams[n]->codec; |
52 | 45 uint8_t *p= codec->extradata; |
53 /* begin vorbis specific code */ | 46 |
54 | 47 for(i=0; i < codec->extradata_size; i+= op->bytes){ |
55 vorbis_info_init(&vi) ; | 48 op->bytes = p[i++]<<8; |
56 | 49 op->bytes+= p[i++]; |
57 /* code copied from libavcodec/oggvorbis.c */ | 50 |
58 | 51 op->packet= &p[i]; |
59 if(oggvorbis_init_encoder(&vi, avccontext) < 0) { | 52 op->b_o_s= op->packetno==0; |
60 fprintf(stderr, "ogg_write_header: init_encoder failed") ; | 53 |
61 return -1 ; | 54 ogg_stream_packetin(&context->os, op); |
62 } | 55 |
63 | 56 op->packetno++; //FIXME multiple streams |
64 vorbis_analysis_init(&vd, &vi) ; | 57 } |
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 */ | |
84 | 58 |
85 context->header_handled = 0 ; | 59 context->header_handled = 0 ; |
86 } | 60 } |
87 | 61 |
88 return 0 ; | 62 return 0 ; |
89 } | 63 } |
90 | |
91 | 64 |
92 static int ogg_write_packet(AVFormatContext *avfcontext, | 65 static int ogg_write_packet(AVFormatContext *avfcontext, |
93 int stream_index, | 66 int stream_index, |
94 const uint8_t *buf, int size, int64_t pts) | 67 const uint8_t *buf, int size, int64_t pts) |
95 { | 68 { |