-/* return the number of packet read to find the codec parameters */
-int find_codec_parameters(AVFormatContext *ic)
-{
- int val, i, count, ret, got_picture, size;
- AVCodec *codec;
- AVCodecContext *enc;
- AVStream *st;
- AVPacket *pkt;
- AVPicture picture;
- AVPacketList *pktl, **ppktl;
- short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
- UINT8 *ptr;
-
- count = 0;
- ppktl = &ic->packet_buffer;
- for(;;) {
- for(i=0;i<ic->nb_streams;i++) {
- enc = &ic->streams[i]->codec;
-
- switch(enc->codec_type) {
- case CODEC_TYPE_AUDIO:
- val = enc->sample_rate;
- break;
- case CODEC_TYPE_VIDEO:
- val = enc->width;
- break;
- default:
- val = 1;
- break;
- }
- /* if no parameters supplied, then we should read it from
- the stream */
- if (val == 0)
- break;
- }
- if (i == ic->nb_streams) {
- ret = count;
- break;
- }
-
- if (count == 0) {
- /* open each codec */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- codec = avcodec_find_decoder(st->codec.codec_id);
- if (codec == NULL) {
- ret = -1;
- goto the_end;
- }
- ret = avcodec_open(&st->codec, codec);
- if (ret < 0)
- goto the_end;
- }
- }
- pktl = av_mallocz(sizeof(AVPacketList));
- if (!pktl) {
- ret = -1;
- break;
- }
-
- /* add the packet in the buffered packet list */
- *ppktl = pktl;
- ppktl = &pktl->next;
-
- pkt = &pktl->pkt;
- if (ic->format->read_packet(ic, pkt) < 0) {
- ret = -1;
- break;
- }
- st = ic->streams[pkt->stream_index];
-
- /* decode the data and update codec parameters */
- ptr = pkt->data;
- size = pkt->size;
- while (size > 0) {
- switch(st->codec.codec_type) {
- case CODEC_TYPE_VIDEO:
- ret = avcodec_decode_video(&st->codec, &picture, &got_picture, ptr, size);
- break;
- case CODEC_TYPE_AUDIO:
- ret = avcodec_decode_audio(&st->codec, samples, &got_picture, ptr, size);
- break;
- default:
- ret = -1;
- break;
- }
- if (ret < 0) {
- ret = -1;
- goto the_end;
- }
- if (got_picture)
- break;
- ptr += ret;
- size -= ret;
- }
-
- count++;
- }
- the_end:
- if (count > 0) {
- /* close each codec */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- avcodec_close(&st->codec);
- }
- }
- return ret;
-}
-
-int filename_number_test(const char *filename)