int nb_frames; /* current frame number */
int total_frames; /* total number of frames */
int num;
- AVCodecContext *enc;
+ AVCodecParameters *par;
} StreamInfo;
typedef struct RMMuxContext {
/* in ms */
#define BUFFER_DURATION 0
+/* the header needs at most 7 + 4 + 12 B */
+#define MAX_HEADER_SIZE (7 + 4 + 12)
+/* UINT16_MAX is the maximal chunk size */
+#define MAX_PACKET_SIZE (UINT16_MAX - MAX_HEADER_SIZE)
static void put_str(AVIOContext *s, const char *tag)
avio_wb32(s, 0); /* data offset : will be patched after */
avio_wb16(s, ctx->nb_streams); /* num streams */
flags = 1 | 2; /* save allowed & perfect play */
- if (!s->seekable)
+ if (!(s->seekable & AVIO_SEEKABLE_NORMAL))
flags |= 4; /* live broadcast */
avio_wb16(s, flags);
stream = &rm->streams[i];
- if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (stream->par->codec_type == AVMEDIA_TYPE_AUDIO) {
desc = "The Audio Stream";
mimetype = "audio/x-pn-realaudio";
codec_data_size = 73;
avio_wb32(s, 0); /* start time */
avio_wb32(s, BUFFER_DURATION); /* preroll */
/* duration */
- if (!s->seekable || !stream->total_frames)
+ if (!(s->seekable & AVIO_SEEKABLE_NORMAL) || !stream->total_frames)
avio_wb32(s, (int)(3600 * 1000));
else
avio_wb32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
put_str8(s, mimetype);
avio_wb32(s, codec_data_size);
- if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
+ if (stream->par->codec_type == AVMEDIA_TYPE_AUDIO) {
int coded_frame_size, fscode, sample_rate;
- sample_rate = stream->enc->sample_rate;
- coded_frame_size = (stream->enc->bit_rate *
- stream->enc->frame_size) / (8 * sample_rate);
+ int frame_size = av_get_audio_frame_duration2(stream->par, 0);
+ sample_rate = stream->par->sample_rate;
+ coded_frame_size = (stream->par->bit_rate *
+ frame_size) / (8 * sample_rate);
/* audio codec info */
avio_write(s, ".ra", 3);
avio_w8(s, 0xfd);
/* frame length : seems to be very important */
avio_wb16(s, coded_frame_size);
avio_wb32(s, 0); /* unknown */
- avio_wb16(s, stream->enc->sample_rate); /* sample rate */
+ avio_wb16(s, stream->par->sample_rate); /* sample rate */
avio_wb32(s, 0x10); /* unknown */
- avio_wb16(s, stream->enc->channels);
+ avio_wb16(s, stream->par->channels);
put_str8(s, "Int0"); /* codec name */
- if (stream->enc->codec_tag) {
+ if (stream->par->codec_tag) {
avio_w8(s, 4); /* tag length */
- avio_wl32(s, stream->enc->codec_tag);
+ avio_wl32(s, stream->par->codec_tag);
} else {
av_log(ctx, AV_LOG_ERROR, "Invalid codec tag\n");
return -1;
/* video codec info */
avio_wb32(s,34); /* size */
ffio_wfourcc(s, "VIDO");
- if(stream->enc->codec_id == AV_CODEC_ID_RV10)
+ if(stream->par->codec_id == AV_CODEC_ID_RV10)
ffio_wfourcc(s,"RV10");
else
ffio_wfourcc(s,"RV20");
- avio_wb16(s, stream->enc->width);
- avio_wb16(s, stream->enc->height);
+ avio_wb16(s, stream->par->width);
+ avio_wb16(s, stream->par->height);
avio_wb16(s, (int) stream->frame_rate); /* frames per seconds ? */
avio_wb32(s,0); /* unknown meaning */
avio_wb16(s, (int) stream->frame_rate); /* unknown meaning */
avio_wb32(s,0); /* unknown meaning */
avio_wb16(s, 8); /* unknown meaning */
- /* Seems to be the codec version: only use basic H263. The next
- versions seems to add a diffential DC coding as in
- MPEG... nothing new under the sun */
- if(stream->enc->codec_id == AV_CODEC_ID_RV10)
+ /* Seems to be the codec version: only use basic H.263. The next
+ versions seems to add a differential DC coding as in
+ MPEG... nothing new under the sun. */
+ if(stream->par->codec_id == AV_CODEC_ID_RV10)
avio_wb32(s,0x10000000);
else
avio_wb32(s,0x20103001);
RMMuxContext *rm = s->priv_data;
StreamInfo *stream;
int n;
- AVCodecContext *codec;
+ AVCodecParameters *par;
for(n=0;n<s->nb_streams;n++) {
AVStream *st = s->streams[n];
+ int frame_size;
s->streams[n]->id = n;
- codec = s->streams[n]->codec;
+ par = s->streams[n]->codecpar;
stream = &rm->streams[n];
memset(stream, 0, sizeof(StreamInfo));
stream->num = n;
- stream->bit_rate = codec->bit_rate;
- stream->enc = codec;
+ stream->bit_rate = par->bit_rate;
+ stream->par = par;
- switch(codec->codec_type) {
+ switch (par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
rm->audio_stream = stream;
- stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
+ frame_size = av_get_audio_frame_duration2(par, 0);
+ stream->frame_rate = (float)par->sample_rate / (float)frame_size;
/* XXX: dummy values */
stream->packet_max_size = 1024;
stream->nb_packets = 0;
static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
{
- uint8_t *buf1;
RMMuxContext *rm = s->priv_data;
AVIOContext *pb = s->pb;
StreamInfo *stream = rm->audio_stream;
int i;
- /* XXX: suppress this malloc */
- buf1 = av_malloc(size * sizeof(uint8_t));
-
write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));
- if (stream->enc->codec_id == AV_CODEC_ID_AC3) {
+ if (stream->par->codec_id == AV_CODEC_ID_AC3) {
/* for AC-3, the words seem to be reversed */
- for(i=0;i<size;i+=2) {
- buf1[i] = buf[i+1];
- buf1[i+1] = buf[i];
+ for (i = 0; i < size; i += 2) {
+ avio_w8(pb, buf[i + 1]);
+ avio_w8(pb, buf[i]);
}
- avio_write(pb, buf1, size);
} else {
avio_write(pb, buf, size);
}
stream->nb_frames++;
- av_free(buf1);
return 0;
}
/* Well, I spent some time finding the meaning of these bits. I am
not sure I understood everything, but it works !! */
-#if 1
+ if (size > MAX_PACKET_SIZE) {
+ avpriv_report_missing_feature(s, "Muxing packets larger than 64 kB");
+ return AVERROR(ENOSYS);
+ }
write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame);
/* bit 7: '1' if final packet of a frame converted in several packets */
avio_w8(pb, 0x81);
- /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
+ /* bit 7: '1' if I-frame. bits 6..0 : sequence number in current
frame starting from 1 */
if (key_frame) {
avio_w8(pb, 0x81);
avio_wb16(pb, 0x4000 | size); /* total frame size */
avio_wb16(pb, 0x4000 | size); /* offset from the start or the end */
}
-#else
- /* full frame */
- write_packet_header(s, size + 6);
- avio_w8(pb, 0xc0);
- avio_wb16(pb, 0x4000 + size); /* total frame size */
- avio_wb16(pb, 0x4000 + packet_number * 126); /* position in stream */
-#endif
avio_w8(pb, stream->nb_frames & 0xff);
avio_write(pb, buf, size);
static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
{
- if (s->streams[pkt->stream_index]->codec->codec_type ==
+ if (s->streams[pkt->stream_index]->codecpar->codec_type ==
AVMEDIA_TYPE_AUDIO)
return rm_write_audio(s, pkt->data, pkt->size, pkt->flags);
else
int data_size, index_pos, i;
AVIOContext *pb = s->pb;
- if (s->pb->seekable) {
+ if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
/* end of file: finish to write header */
index_pos = avio_tell(pb);
data_size = index_pos - rm->data_pos;