annotate avisynth.c @ 1336:06a5d191774d libavformat

move sample size adjusting code after audio stsd v2 parsing to let v2 set correct channel number, fix Sony-hdv2.mov
author bcoudurier
date Thu, 28 Sep 2006 17:59:26 +0000
parents 516cb8ef781a
children 3637b5c4e882
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1283
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
1 /*
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
2 * AVISynth support for ffmpeg system
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
3 * Copyright (c) 2006 DivX, Inc.
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
4 *
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
9 *
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
13 * Lesser General Public License for more details.
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
14 *
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
18 */
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
19
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
20 #include "avformat.h"
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
21 #include "riff.h"
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
22
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
23 #include <windows.h>
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
24 #include <vfw.h>
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
25
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
26 typedef struct {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
27 PAVISTREAM handle;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
28 AVISTREAMINFO info;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
29 DWORD read;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
30 LONG chunck_size;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
31 LONG chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
32 } AVISynthStream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
33
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
34 typedef struct {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
35 PAVIFILE file;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
36 AVISynthStream *streams;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
37 int nb_streams;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
38 int next_stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
39 } AVISynthContext;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
40
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
41 static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
42 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
43 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
44 HRESULT res;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
45 AVIFILEINFO info;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
46 DWORD id;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
47 AVStream *st;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
48 AVISynthStream *stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
49
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
50 AVIFileInit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
51
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
52 res = AVIFileOpen(&avs->file, s->filename, OF_READ|OF_SHARE_DENY_WRITE, NULL);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
53 if (res != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
54 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
55 av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
56 AVIFileExit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
57 return -1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
58 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
59
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
60 res = AVIFileInfo(avs->file, &info, sizeof(info));
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
61 if (res != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
62 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
63 av_log(s, AV_LOG_ERROR, "AVIFileInfo failed with error %ld", res);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
64 AVIFileExit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
65 return -1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
66 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
67
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
68 avs->streams = av_mallocz(info.dwStreams * sizeof(AVISynthStream));
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
69
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
70 for (id=0; id<info.dwStreams; id++)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
71 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
72 stream = &avs->streams[id];
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
73 stream->read = 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
74 if (AVIFileGetStream(avs->file, &stream->handle, 0, id) == S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
75 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
76 if (AVIStreamInfo(stream->handle, &stream->info, sizeof(stream->info)) == S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
77 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
78 if (stream->info.fccType == streamtypeAUDIO)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
79 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
80 WAVEFORMATEX wvfmt;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
81 LONG struct_size = sizeof(WAVEFORMATEX);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
82 if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
83 continue;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
84
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
85 st = av_new_stream(s, id);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
86 st->codec->codec_type = CODEC_TYPE_AUDIO;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
87
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
88 st->codec->block_align = wvfmt.nBlockAlign;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
89 st->codec->channels = wvfmt.nChannels;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
90 st->codec->sample_rate = wvfmt.nSamplesPerSec;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
91 st->codec->bit_rate = wvfmt.nAvgBytesPerSec * 8;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
92 st->codec->bits_per_sample = wvfmt.wBitsPerSample;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
93
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
94 stream->chunck_samples = wvfmt.nSamplesPerSec * (uint64_t)info.dwScale / (uint64_t)info.dwRate;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
95 stream->chunck_size = stream->chunck_samples * wvfmt.nChannels * wvfmt.wBitsPerSample / 8;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
96
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
97 st->codec->codec_id = wav_codec_get_id(wvfmt.wFormatTag, st->codec->bits_per_sample);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
98 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
99 else if (stream->info.fccType == streamtypeVIDEO)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
100 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
101 BITMAPINFO imgfmt;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
102 LONG struct_size = sizeof(BITMAPINFO);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
103
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
104 stream->chunck_size = stream->info.dwSampleSize;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
105 stream->chunck_samples = 1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
106
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
107 if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
108 continue;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
109
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
110 st = av_new_stream(s, id);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
111 st->codec->codec_type = CODEC_TYPE_VIDEO;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
112 st->r_frame_rate.num = stream->info.dwRate;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
113 st->r_frame_rate.den = stream->info.dwScale;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
114
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
115 st->codec->width = imgfmt.bmiHeader.biWidth;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
116 st->codec->height = imgfmt.bmiHeader.biHeight;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
117
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
118 st->codec->bits_per_sample = stream->info.dwSampleSize * 8;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
119 st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
120 st->codec->codec_id = codec_get_id(codec_bmp_tags, stream->info.fccHandler);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
121
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
122 st->duration = stream->info.dwLength;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
123 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
124 else
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
125 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
126 AVIStreamRelease(stream->handle);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
127 continue;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
128 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
129
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
130 avs->nb_streams++;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
131 st->codec->codec_tag = stream->info.fccHandler;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
132
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
133 st->codec->stream_codec_tag = stream->info.fccHandler;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
134
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
135 av_set_pts_info(st, 64, info.dwScale, info.dwRate);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
136 st->start_time = stream->info.dwStart;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
137 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
138 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
139 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
140
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
141 return 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
142 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
143
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
144 static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
145 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
146 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
147 HRESULT res;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
148 AVISynthStream *stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
149 int stream_id = avs->next_stream;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
150 LONG read_size;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
151
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
152 // handle interleaving manually...
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
153 stream = &avs->streams[stream_id];
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
154
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
155 if (stream->read >= stream->info.dwLength)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
156 return AVERROR_IO;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
157
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
158 if (av_new_packet(pkt, stream->chunck_size))
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
159 return AVERROR_IO;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
160 pkt->stream_index = stream_id;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
161 pkt->pts = avs->streams[stream_id].read / avs->streams[stream_id].chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
162
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
163 res = AVIStreamRead(stream->handle, stream->read, stream->chunck_samples, pkt->data, stream->chunck_size, &read_size, NULL);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
164
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
165 pkt->pts = stream->read;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
166 pkt->size = read_size;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
167
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
168 stream->read += stream->chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
169
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
170 // prepare for the next stream to read
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
171 do {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
172 avs->next_stream = (avs->next_stream+1) % avs->nb_streams;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
173 } while (avs->next_stream != stream_id && s->streams[avs->next_stream]->discard >= AVDISCARD_ALL);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
174
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
175 return (res == S_OK) ? pkt->size : -1;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
176 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
177
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
178 static int avisynth_read_close(AVFormatContext *s)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
179 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
180 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
181 int i;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
182
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
183 for (i=0;i<avs->nb_streams;i++)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
184 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
185 AVIStreamRelease(avs->streams[i].handle);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
186 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
187
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
188 av_free(avs->streams);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
189 AVIFileRelease(avs->file);
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
190 AVIFileExit();
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
191 return 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
192 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
193
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
194 static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
195 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
196 AVISynthContext *avs = s->priv_data;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
197 int stream_id;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
198
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
199 for (stream_id = 0; stream_id < avs->nb_streams; stream_id++)
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
200 {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
201 avs->streams[stream_id].read = pts * avs->streams[stream_id].chunck_samples;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
202 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
203
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
204 return 0;
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
205 }
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
206
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
207 AVInputFormat avisynth_demuxer = {
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
208 "avs",
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
209 "AVISynth",
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
210 sizeof(AVISynthContext),
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
211 NULL,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
212 avisynth_read_header,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
213 avisynth_read_packet,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
214 avisynth_read_close,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
215 avisynth_read_seek,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
216 NULL,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
217 0,
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
218 "avs",
516cb8ef781a Add missing file from commit r6122 (AVISynth support)
gpoirier
parents:
diff changeset
219 };