1 /*
2 * TechnoTrend PVA (.pva) demuxer
3 * Copyright (c) 2007, 2008 Ivo van Poorten
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
25
26 #define PVA_MAX_PAYLOAD_LENGTH 0x17f8
27 #define PVA_VIDEO_PAYLOAD 0x01
28 #define PVA_AUDIO_PAYLOAD 0x02
29 #define PVA_MAGIC (('A' << 8) + 'V')
30
34
39 return -1;
40 return length + 8;
41 }
42
44 const unsigned char *
buf = pd->
buf;
46
47 if (len < 0)
48 return 0;
49
53
55 }
56
59
67
75
76 /* the parameters will be extracted from the compressed bitstream */
77 return 0;
78 }
79
80 #define pva_log if (read_packet) av_log
81
86 int syncword, streamid, reserved,
flags,
length, pts_flag;
88 int ret;
89
92
95 avio_r8(pb);
/* counter not used */
99
100 pts_flag = flags & 0x10;
101
105 }
109 }
110 if (reserved != 0x55) {
112 }
116 }
117
120 length -= 4;
122 /* PVA Audio Packets either start with a signaled PES packet or
123 * are a continuation of the previous PES packet. New PES packets
124 * always start at the beginning of a PVA Packet, never somewhere in
125 * the middle. */
127 int pes_signal, pes_header_data_length, pes_packet_length,
128 pes_flags;
129 unsigned char pes_header_data[256];
130
135 pes_header_data_length =
avio_r8(pb);
136
137 if (pes_signal != 1 || pes_header_data_length == 0) {
139 "trying to recover\n");
141 if (!read_packet)
144 }
145
146 ret =
avio_read(pb, pes_header_data, pes_header_data_length);
147 if (ret != pes_header_data_length)
149 length -= 9 + pes_header_data_length;
150
151 pes_packet_length -= 3 + pes_header_data_length;
152
154
155 if (pes_flags & 0x80 && (pes_header_data[0] & 0xf0) == 0x20) {
156 if (pes_header_data_length < 5) {
160 }
162 }
163 }
164
166
170 }
171 }
172
175
176 *pts = pva_pts;
178 *strid = streamid;
179 return 0;
180 }
181
184 int64_t pva_pts;
185 int ret,
length, streamid;
186
190
193
194 return ret;
195 }
196
198 int64_t *pos, int64_t pos_limit) {
203
205
206 while (*pos < pos_limit) {
209
212 (*pos)++;
213 continue;
214 }
217 continue;
218 }
219 break;
220 }
221
223 return res;
224 }
225
234 };
static int recover(WtvContext *wtv, uint64_t broken_pos)
Try to seek over a broken chunk.
static int pva_read_packet(AVFormatContext *s, AVPacket *pkt)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int pva_read_header(AVFormatContext *s)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
unsigned int avio_rb16(AVIOContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
#define PVA_VIDEO_PAYLOAD
static int read_part_of_packet(AVFormatContext *s, int64_t *pts, int *len, int *strid, int read_packet)
unsigned int avio_rb32(AVIOContext *s)
enum AVStreamParseType need_parsing
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int pva_check(const uint8_t *p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int64_t ff_parse_pes_pts(const uint8_t *buf)
Parse MPEG-PES five-byte timestamp.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define PVA_AUDIO_PAYLOAD
unsigned int avio_rb24(AVIOContext *s)
static int64_t pva_read_timestamp(struct AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit)
AVInputFormat ff_pva_demuxer
preferred ID for MPEG-1/2 video decoding
static int read_header(FFV1Context *f)
#define PVA_MAX_PAYLOAD_LENGTH
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
enum AVMediaType codec_type
AVIOContext * pb
I/O context.
This structure contains the data a format has to probe a file.
static int64_t pts
Global timestamp for the audio frames.
static int pva_probe(AVProbeData *pd)
void * priv_data
Format private data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.