Mercurial > libavformat.hg
comparison rmenc.c @ 6065:441608273a5c libavformat
Use ff_rm_codec_tags[] in RM muxer. This, incidentally, also allows muxing
other audio codecs rather than only AC-3, so add some code that makes
word byte-swapping only happen for AC-3, not for all audio codecs.
Patch by Francesco Lavra <francescolavra interfree it>.
author | rbultje |
---|---|
date | Fri, 28 May 2010 18:21:25 +0000 |
parents | 11bb10c37225 |
children | 490c440a53e7 |
comparison
equal
deleted
inserted
replaced
6064:87e28edf7a98 | 6065:441608273a5c |
---|---|
58 while (*tag) { | 58 while (*tag) { |
59 put_byte(s, *tag++); | 59 put_byte(s, *tag++); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 static void rv10_write_header(AVFormatContext *ctx, | 63 static int rv10_write_header(AVFormatContext *ctx, |
64 int data_size, int index_pos) | 64 int data_size, int index_pos) |
65 { | 65 { |
66 RMMuxContext *rm = ctx->priv_data; | 66 RMMuxContext *rm = ctx->priv_data; |
67 ByteIOContext *s = ctx->pb; | 67 ByteIOContext *s = ctx->pb; |
68 StreamInfo *stream; | 68 StreamInfo *stream; |
223 put_be32(s, 0); /* unknown */ | 223 put_be32(s, 0); /* unknown */ |
224 put_be16(s, stream->enc->sample_rate); /* sample rate */ | 224 put_be16(s, stream->enc->sample_rate); /* sample rate */ |
225 put_be32(s, 0x10); /* unknown */ | 225 put_be32(s, 0x10); /* unknown */ |
226 put_be16(s, stream->enc->channels); | 226 put_be16(s, stream->enc->channels); |
227 put_str8(s, "Int0"); /* codec name */ | 227 put_str8(s, "Int0"); /* codec name */ |
228 put_str8(s, "dnet"); /* codec name */ | 228 if (stream->enc->codec_tag) { |
229 put_byte(s, 4); /* tag length */ | |
230 put_le32(s, stream->enc->codec_tag); | |
231 } else { | |
232 av_log(ctx, AV_LOG_ERROR, "Invalid codec tag\n"); | |
233 return -1; | |
234 } | |
229 put_be16(s, 0); /* title length */ | 235 put_be16(s, 0); /* title length */ |
230 put_be16(s, 0); /* author length */ | 236 put_be16(s, 0); /* author length */ |
231 put_be16(s, 0); /* copyright length */ | 237 put_be16(s, 0); /* copyright length */ |
232 put_byte(s, 0); /* end of header */ | 238 put_byte(s, 0); /* end of header */ |
233 } else { | 239 } else { |
268 put_be32(s,data_size + 10 + 8); | 274 put_be32(s,data_size + 10 + 8); |
269 put_be16(s,0); | 275 put_be16(s,0); |
270 | 276 |
271 put_be32(s, nb_packets); /* number of packets */ | 277 put_be32(s, nb_packets); /* number of packets */ |
272 put_be32(s,0); /* next data header */ | 278 put_be32(s,0); /* next data header */ |
279 return 0; | |
273 } | 280 } |
274 | 281 |
275 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream, | 282 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream, |
276 int length, int key_frame) | 283 int length, int key_frame) |
277 { | 284 { |
328 default: | 335 default: |
329 return -1; | 336 return -1; |
330 } | 337 } |
331 } | 338 } |
332 | 339 |
333 rv10_write_header(s, 0, 0); | 340 if (rv10_write_header(s, 0, 0)) |
341 return AVERROR_INVALIDDATA; | |
334 put_flush_packet(s->pb); | 342 put_flush_packet(s->pb); |
335 return 0; | 343 return 0; |
336 } | 344 } |
337 | 345 |
338 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags) | 346 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags) |
346 /* XXX: suppress this malloc */ | 354 /* XXX: suppress this malloc */ |
347 buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) ); | 355 buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) ); |
348 | 356 |
349 write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY)); | 357 write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY)); |
350 | 358 |
359 if (stream->enc->codec_id == CODEC_ID_AC3) { | |
351 /* for AC-3, the words seem to be reversed */ | 360 /* for AC-3, the words seem to be reversed */ |
352 for(i=0;i<size;i+=2) { | 361 for(i=0;i<size;i+=2) { |
353 buf1[i] = buf[i+1]; | 362 buf1[i] = buf[i+1]; |
354 buf1[i+1] = buf[i]; | 363 buf1[i+1] = buf[i]; |
355 } | 364 } |
356 put_buffer(pb, buf1, size); | 365 put_buffer(pb, buf1, size); |
366 } else { | |
367 put_buffer(pb, buf, size); | |
368 } | |
357 put_flush_packet(pb); | 369 put_flush_packet(pb); |
358 stream->nb_frames++; | 370 stream->nb_frames++; |
359 av_free(buf1); | 371 av_free(buf1); |
360 return 0; | 372 return 0; |
361 } | 373 } |
454 CODEC_ID_AC3, | 466 CODEC_ID_AC3, |
455 CODEC_ID_RV10, | 467 CODEC_ID_RV10, |
456 rm_write_header, | 468 rm_write_header, |
457 rm_write_packet, | 469 rm_write_packet, |
458 rm_write_trailer, | 470 rm_write_trailer, |
471 .codec_tag= (const AVCodecTag* const []){ff_rm_codec_tags, 0}, | |
459 }; | 472 }; |