1 /*
2 * Digital Speech Standard (DSS) demuxer
3 * Copyright (c) 2014 Oleksij Rempel <linux@rempel-privat.de>
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
26
29
30 #define DSS_HEAD_OFFSET_AUTHOR 0xc
31 #define DSS_AUTHOR_SIZE 16
32
33 #define DSS_HEAD_OFFSET_START_TIME 0x26
34 #define DSS_HEAD_OFFSET_END_TIME 0x32
35 #define DSS_TIME_SIZE 12
36
37 #define DSS_HEAD_OFFSET_ACODEC 0x2a4
38 #define DSS_ACODEC_DSS_SP 0x0 /* SP mode */
39 #define DSS_ACODEC_G723_1 0x2 /* LP mode */
40
41 #define DSS_HEAD_OFFSET_COMMENT 0x31e
42 #define DSS_COMMENT_SIZE 64
43
44 #define DSS_BLOCK_SIZE 512
45 #define DSS_HEADER_SIZE (DSS_BLOCK_SIZE * 2)
46 #define DSS_AUDIO_BLOCK_HEADER_SIZE 6
47 #define DSS_FRAME_SIZE 42
48
50
57
60
62 {
64 return 0;
65
67 }
68
70 const char *key)
71 {
74 int y, month, d,
h, minute, sec;
75 int ret;
76
78
82
83 if (sscanf(string, "%2d%2d%2d%2d%2d%2d", &y, &month, &d, &h, &minute, &sec) != 6)
85 /* We deal with a two-digit year here, so set the default date to 2000
86 * and hope it will never be used in the next century. */
87 snprintf(datetime,
sizeof(datetime),
"%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
88 y + 2000, month, d, h, minute, sec);
90 }
91
93 unsigned int size,
const char *key)
94 {
97 int ret;
98
100
102 if (!value)
104
106 if (ret < size) {
108 goto exit;
109 }
110
112
113 exit:
115 return ret;
116 }
117
119 {
123 int ret;
124
126 if (!st)
128
131 if (ret)
132 return ret;
133
135 if (ret)
136 return ret;
137
140 if (ret)
141 return ret;
142
145
152 } else {
156 }
157
161
164
165 /* Jump over header */
166
169
172
176
177 return 0;
178 }
179
181 {
184
187 }
188
191 {
192 int i;
193
196 dst[i] = src[i];
197
198 for (i = 0; i < DSS_FRAME_SIZE - 2; i += 2)
199 dst[i] = src[i + 4];
200
202 } else {
205 }
206
207 /* make sure byte 40 is always 0 */
210 }
211
213 {
216 int read_size, ret,
offset = 0, buff_offset = 0;
218
221
224 buff_offset = 3;
225 } else
227
230
232 if (ret < 0)
233 return ret;
234
239
241 int size2 = ctx->
counter + read_size;
242
244 size2 - offset);
245 if (ret < size2 - offset)
246 goto error_eof;
247
249 offset = size2;
250 }
251
253 read_size - offset);
254 if (ret < read_size - offset)
255 goto error_eof;
256
258
261 goto error_eof;
262 }
263
264 if (pkt->
data[0] == 0xff)
266
268
269 error_eof:
272 }
273
275 {
280
283
284 /* We make one byte-step here. Don't forget to add offset. */
286 if (byte == 0xff)
288
290
293
295 if (ret < 0)
296 return ret;
298
300 offset = 1;
303
305
308
310 size2 - offset);
311 if (ret < size2 - offset) {
314 }
315
317 offset = size2;
318 }
319
321 if (ret < size - offset) {
324 }
325
327 }
328
330 {
332
335 else
337 }
338
340 {
342
344
345 return 0;
346 }
347
349 int64_t timestamp,
int flags)
350 {
352 int64_t ret, seekto;
355
357 seekto = timestamp / 264 * 41 / 506 * 512;
358 else
359 seekto = timestamp / 240 * ctx->
packet_size / 506 * 512;
360
361 if (seekto < 0)
362 seekto = 0;
363
365
367 if (ret < 0)
368 return ret;
369
371 ctx->
swap = !!(header[0] & 0x80);
372 offset = 2*header[1] + 2*ctx->
swap;
378 } else {
381 }
383 return 0;
384 }
385
386
396 .extensions = "dss"
397 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t pos
byte position in stream, -1 if unknown
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
AVInputFormat ff_dss_demuxer
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
#define DSS_AUDIO_BLOCK_HEADER_SIZE
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static void dss_skip_audio_header(AVFormatContext *s, AVPacket *pkt)
Macro definitions for various function/variable attributes.
#define DSS_HEAD_OFFSET_AUTHOR
static int dss_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int dss_read_close(AVFormatContext *s)
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 int dss_read_header(AVFormatContext *s)
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVDictionary * metadata
Metadata that applies to the whole file.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
static const uint8_t offset[127][2]
static int dss_read_packet(AVFormatContext *s, AVPacket *pkt)
uint64_t channel_layout
Audio channel layout.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
audio channel layout utility functions
#define DSS_HEAD_OFFSET_END_TIME
static int dss_probe(AVProbeData *p)
GLsizei GLboolean const GLfloat * value
static void dss_sp_byte_swap(DSSDemuxContext *ctx, uint8_t *dst, const uint8_t *src)
#define DSS_HEAD_OFFSET_COMMENT
static int dss_read_metadata_string(AVFormatContext *s, unsigned int offset, unsigned int size, const char *key)
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
enum AVMediaType codec_type
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_WB16 unsigned int_TMPL byte
int sample_rate
samples per second
AVIOContext * pb
I/O context.
#define DSS_HEAD_OFFSET_ACODEC
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static const uint8_t frame_size[4]
This structure contains the data a format has to probe a file.
#define DSS_ACODEC_G723_1
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
#define DSS_ACODEC_DSS_SP
int channels
number of audio channels
void * priv_data
Format private data.
static int dss_read_metadata_date(AVFormatContext *s, unsigned int offset, const char *key)
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...