1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

complete handling of pcm formats - hex dump option

Originally committed as revision 138 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Fabrice Bellard 2001-09-23 17:14:51 +00:00
parent d2b7bcd23f
commit a0663ba4b0

View File

@ -96,6 +96,7 @@ static char *str_author = NULL;
static char *str_copyright = NULL; static char *str_copyright = NULL;
static char *str_comment = NULL; static char *str_comment = NULL;
static int do_benchmark = 0; static int do_benchmark = 0;
static int do_hex_dump = 0;
typedef struct AVOutputStream { typedef struct AVOutputStream {
int file_index; /* file index */ int file_index; /* file index */
@ -648,7 +649,7 @@ static void do_audio_out(AVFormatContext *s,
} }
/* now encode as many frames as possible */ /* now encode as many frames as possible */
if (enc->codec_id != CODEC_ID_PCM) { if (enc->frame_size > 1) {
/* output resampled raw samples */ /* output resampled raw samples */
fifo_write(&ost->fifo, buftmp, size_out, fifo_write(&ost->fifo, buftmp, size_out,
&ost->fifo.wptr); &ost->fifo.wptr);
@ -657,13 +658,26 @@ static void do_audio_out(AVFormatContext *s,
while (fifo_read(&ost->fifo, audio_buf, frame_bytes, while (fifo_read(&ost->fifo, audio_buf, frame_bytes,
&ost->fifo.rptr) == 0) { &ost->fifo.rptr) == 0) {
ret = avcodec_encode_audio(enc, ret = avcodec_encode_audio(enc, audio_out, sizeof(audio_out),
audio_out, sizeof(audio_out), (short *)audio_buf); (short *)audio_buf);
s->format->write_packet(s, ost->index, audio_out, ret); s->format->write_packet(s, ost->index, audio_out, ret);
} }
} else { } else {
/* XXX: handle endianness */ /* output a pcm frame */
s->format->write_packet(s, ost->index, buftmp, size_out); /* XXX: change encoding codec API to avoid this ? */
switch(enc->codec->id) {
case CODEC_ID_PCM_S16LE:
case CODEC_ID_PCM_S16BE:
case CODEC_ID_PCM_U16LE:
case CODEC_ID_PCM_U16BE:
break;
default:
size_out = size_out >> 1;
break;
}
ret = avcodec_encode_audio(enc, audio_out, size_out,
(short *)buftmp);
s->format->write_packet(s, ost->index, audio_out, ret);
} }
} }
@ -860,9 +874,6 @@ static void do_video_out(AVFormatContext *s,
free(buf1); free(buf1);
} }
//#define HEX_DUMP
#ifdef HEX_DUMP
static void hex_dump(UINT8 *buf, int size) static void hex_dump(UINT8 *buf, int size)
{ {
int len, i, j, c; int len, i, j, c;
@ -888,7 +899,6 @@ static void hex_dump(UINT8 *buf, int size)
printf("\n"); printf("\n");
} }
} }
#endif
/* /*
* The following code is the main loop of the file converter * The following code is the main loop of the file converter
@ -1191,10 +1201,10 @@ static int av_encode(AVFormatContext **output_files,
continue; continue;
} }
#ifdef HEX_DUMP if (do_hex_dump) {
printf("stream #%d, size=%d:\n", pkt.stream_index, pkt.size); printf("stream #%d, size=%d:\n", pkt.stream_index, pkt.size);
hex_dump(pkt.data, pkt.size); hex_dump(pkt.data, pkt.size);
#endif }
// printf("read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size); // printf("read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
@ -1208,24 +1218,19 @@ static int av_encode(AVFormatContext **output_files,
if (ist->decoding_needed) { if (ist->decoding_needed) {
switch(ist->st->codec.codec_type) { switch(ist->st->codec.codec_type) {
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
if (ist->st->codec.codec_id == CODEC_ID_PCM) { /* XXX: could avoid copy if PCM 16 bits with same
/* no need to call a codec */ endianness as CPU */
data_buf = ptr; ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size,
data_size = len; ptr, len);
ret = len; if (ret < 0)
} else { goto fail_decode;
ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size, if (data_size == 0) {
ptr, len); /* no audio frame */
if (ret < 0) ptr += ret;
goto fail_decode; len -= ret;
if (data_size == 0) { continue;
/* no audio frame */
ptr += ret;
len -= ret;
continue;
}
data_buf = (UINT8 *)samples;
} }
data_buf = (UINT8 *)samples;
break; break;
case CODEC_TYPE_VIDEO: case CODEC_TYPE_VIDEO:
if (ist->st->codec.codec_id == CODEC_ID_RAWVIDEO) { if (ist->st->codec.codec_id == CODEC_ID_RAWVIDEO) {
@ -2230,6 +2235,8 @@ const OptionDef options[] = {
"deinterlace pictures" }, "deinterlace pictures" },
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark}, { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
"add timings for benchmarking" }, "add timings for benchmarking" },
{ "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
"dump each input packet" },
{ NULL, }, { NULL, },
}; };