2009-01-20 07:42:14 +00:00
|
|
|
/*
|
|
|
|
* R3D REDCODE demuxer
|
|
|
|
* Copyright (c) 2008 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/intreadwrite.h"
|
2011-05-22 10:46:29 +00:00
|
|
|
#include "libavutil/dict.h"
|
2011-06-04 11:58:23 +00:00
|
|
|
#include "libavutil/mathematics.h"
|
2009-01-20 07:42:14 +00:00
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2014-09-22 07:19:33 +00:00
|
|
|
typedef struct R3DContext {
|
2009-01-20 07:42:14 +00:00
|
|
|
unsigned video_offsets_count;
|
|
|
|
unsigned *video_offsets;
|
|
|
|
unsigned rdvo_offset;
|
|
|
|
} R3DContext;
|
|
|
|
|
2014-09-22 07:19:33 +00:00
|
|
|
typedef struct Atom {
|
2009-01-20 07:42:14 +00:00
|
|
|
unsigned size;
|
|
|
|
uint32_t tag;
|
|
|
|
uint64_t offset;
|
|
|
|
} Atom;
|
|
|
|
|
|
|
|
static int read_atom(AVFormatContext *s, Atom *atom)
|
|
|
|
{
|
2011-03-03 19:11:45 +00:00
|
|
|
atom->offset = avio_tell(s->pb);
|
2011-02-21 15:43:01 +00:00
|
|
|
atom->size = avio_rb32(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (atom->size < 8)
|
|
|
|
return -1;
|
2011-02-21 15:43:01 +00:00
|
|
|
atom->tag = avio_rl32(s->pb);
|
2011-05-31 19:23:45 +00:00
|
|
|
av_dlog(s, "atom %u %.4s offset %#"PRIx64"\n",
|
2009-01-20 07:42:14 +00:00
|
|
|
atom->size, (char*)&atom->tag, atom->offset);
|
|
|
|
return atom->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_read_red1(AVFormatContext *s)
|
|
|
|
{
|
2011-06-18 09:43:24 +00:00
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
2009-03-01 15:28:56 +00:00
|
|
|
char filename[258];
|
2011-06-03 11:52:29 +00:00
|
|
|
int tmp;
|
|
|
|
int av_unused tmp2;
|
2012-03-02 13:08:11 +00:00
|
|
|
AVRational framerate;
|
2009-01-20 07:42:14 +00:00
|
|
|
|
|
|
|
if (!st)
|
2009-08-25 19:59:38 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2010-03-30 23:30:55 +00:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
2012-08-05 09:11:04 +00:00
|
|
|
st->codec->codec_id = AV_CODEC_ID_JPEG2000;
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_r8(s->pb); // major version
|
|
|
|
tmp2 = avio_r8(s->pb); // minor version
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "version %d.%d\n", tmp, tmp2);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb16(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown1 %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(st, 32, 1, tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb); // filenum
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "filenum %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(s->pb, 32); // unknown
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
st->codec->width = avio_rb32(s->pb);
|
|
|
|
st->codec->height = avio_rb32(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb16(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown2 %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2012-03-02 13:08:11 +00:00
|
|
|
framerate.num = avio_rb16(s->pb);
|
|
|
|
framerate.den = avio_rb16(s->pb);
|
2013-09-19 14:02:36 +00:00
|
|
|
if (framerate.num > 0 && framerate.den > 0) {
|
2012-06-26 11:10:01 +00:00
|
|
|
#if FF_API_R_FRAME_RATE
|
|
|
|
st->r_frame_rate =
|
|
|
|
#endif
|
|
|
|
st->avg_frame_rate = framerate;
|
|
|
|
}
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_r8(s->pb); // audio channels
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "audio channels %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (tmp > 0) {
|
2011-06-18 09:43:24 +00:00
|
|
|
AVStream *ast = avformat_new_stream(s, NULL);
|
2009-08-25 19:58:21 +00:00
|
|
|
if (!ast)
|
|
|
|
return AVERROR(ENOMEM);
|
2010-03-30 23:30:55 +00:00
|
|
|
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
2012-08-05 09:11:04 +00:00
|
|
|
ast->codec->codec_id = AV_CODEC_ID_PCM_S32BE;
|
2009-01-20 07:42:14 +00:00
|
|
|
ast->codec->channels = tmp;
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(ast, 32, 1, st->time_base.den);
|
2009-01-20 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
avio_read(s->pb, filename, 257);
|
2009-03-01 15:28:56 +00:00
|
|
|
filename[sizeof(filename)-1] = 0;
|
2011-05-22 10:46:29 +00:00
|
|
|
av_dict_set(&st->metadata, "filename", filename, 0);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "filename %s\n", filename);
|
|
|
|
av_dlog(s, "resolution %dx%d\n", st->codec->width, st->codec->height);
|
|
|
|
av_dlog(s, "timescale %d\n", st->time_base.den);
|
|
|
|
av_dlog(s, "frame rate %d/%d\n",
|
2012-03-02 13:08:11 +00:00
|
|
|
framerate.num, framerate.den);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
|
|
|
|
{
|
|
|
|
R3DContext *r3d = s->priv_data;
|
|
|
|
AVStream *st = s->streams[0];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
r3d->video_offsets_count = (atom->size - 8) / 4;
|
|
|
|
r3d->video_offsets = av_malloc(atom->size);
|
|
|
|
if (!r3d->video_offsets)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
for (i = 0; i < r3d->video_offsets_count; i++) {
|
2011-02-21 15:43:01 +00:00
|
|
|
r3d->video_offsets[i] = avio_rb32(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (!r3d->video_offsets[i]) {
|
|
|
|
r3d->video_offsets_count = i;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]);
|
2009-01-20 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 11:10:01 +00:00
|
|
|
if (st->avg_frame_rate.num)
|
2012-03-02 13:08:11 +00:00
|
|
|
st->duration = av_rescale_q(r3d->video_offsets_count,
|
2012-08-05 21:25:27 +00:00
|
|
|
av_inv_q(st->avg_frame_rate),
|
2012-03-02 13:08:11 +00:00
|
|
|
st->time_base);
|
2011-05-29 19:07:35 +00:00
|
|
|
av_dlog(s, "duration %"PRId64"\n", st->duration);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void r3d_read_reos(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
R3DContext *r3d = s->priv_data;
|
2011-06-03 11:52:29 +00:00
|
|
|
int av_unused tmp;
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
r3d->rdvo_offset = avio_rb32(s->pb);
|
|
|
|
avio_rb32(s->pb); // rdvs offset
|
|
|
|
avio_rb32(s->pb); // rdao offset
|
|
|
|
avio_rb32(s->pb); // rdas offset
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "num video chunks %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "num audio chunks %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(s->pb, 6*4);
|
2009-01-20 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 12:20:36 +00:00
|
|
|
static int r3d_read_header(AVFormatContext *s)
|
2009-01-20 07:42:14 +00:00
|
|
|
{
|
|
|
|
R3DContext *r3d = s->priv_data;
|
|
|
|
Atom atom;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (read_atom(s, &atom) < 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "error reading atom\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (atom.tag == MKTAG('R','E','D','1')) {
|
|
|
|
if ((ret = r3d_read_red1(s)) < 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "error parsing 'red1' atom\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
av_log(s, AV_LOG_ERROR, "could not find 'red1' atom\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-06 13:53:40 +00:00
|
|
|
s->internal->data_offset = avio_tell(s->pb);
|
|
|
|
av_dlog(s, "data offset %#"PRIx64"\n", s->internal->data_offset);
|
2011-03-05 20:06:46 +00:00
|
|
|
if (!s->pb->seekable)
|
2009-01-20 07:42:14 +00:00
|
|
|
return 0;
|
|
|
|
// find REOB/REOF/REOS to load index
|
2011-03-04 18:57:36 +00:00
|
|
|
avio_seek(s->pb, avio_size(s->pb)-48-8, SEEK_SET);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (read_atom(s, &atom) < 0)
|
|
|
|
av_log(s, AV_LOG_ERROR, "error reading end atom\n");
|
|
|
|
|
|
|
|
if (atom.tag != MKTAG('R','E','O','B') &&
|
|
|
|
atom.tag != MKTAG('R','E','O','F') &&
|
|
|
|
atom.tag != MKTAG('R','E','O','S'))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
r3d_read_reos(s);
|
|
|
|
|
|
|
|
if (r3d->rdvo_offset) {
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(s->pb, r3d->rdvo_offset, SEEK_SET);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (read_atom(s, &atom) < 0)
|
|
|
|
av_log(s, AV_LOG_ERROR, "error reading 'rdvo' atom\n");
|
|
|
|
if (atom.tag == MKTAG('R','D','V','O')) {
|
|
|
|
if (r3d_read_rdvo(s, &atom) < 0)
|
|
|
|
av_log(s, AV_LOG_ERROR, "error parsing 'rdvo' atom\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2015-02-06 13:53:40 +00:00
|
|
|
avio_seek(s->pb, s->internal->data_offset, SEEK_SET);
|
2009-01-20 07:42:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
|
|
|
|
{
|
|
|
|
AVStream *st = s->streams[0];
|
2011-06-03 11:52:29 +00:00
|
|
|
int tmp;
|
|
|
|
int av_unused tmp2;
|
2015-02-02 01:39:00 +00:00
|
|
|
int64_t pos = avio_tell(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
unsigned dts;
|
2010-03-02 21:32:29 +00:00
|
|
|
int ret;
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
dts = avio_rb32(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "frame num %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_r8(s->pb); // major version
|
|
|
|
tmp2 = avio_r8(s->pb); // minor version
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "version %d.%d\n", tmp, tmp2);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb16(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
|
|
|
if (tmp > 4) {
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb16(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb16(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "width %d\n", tmp);
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "height %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "metadata len %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
}
|
2011-03-03 19:11:45 +00:00
|
|
|
tmp = atom->size - 8 - (avio_tell(s->pb) - pos);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (tmp < 0)
|
|
|
|
return -1;
|
2010-03-02 21:32:29 +00:00
|
|
|
ret = av_get_packet(s->pb, pkt, tmp);
|
|
|
|
if (ret < 0) {
|
2009-01-20 07:42:14 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "error reading video packet\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
pkt->dts = dts;
|
2012-06-26 11:10:01 +00:00
|
|
|
if (st->avg_frame_rate.num)
|
2009-01-20 07:42:14 +00:00
|
|
|
pkt->duration = (uint64_t)st->time_base.den*
|
2012-06-26 11:10:01 +00:00
|
|
|
st->avg_frame_rate.den/st->avg_frame_rate.num;
|
2011-05-29 19:07:35 +00:00
|
|
|
av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
|
|
|
|
{
|
|
|
|
AVStream *st = s->streams[1];
|
2011-06-03 11:52:29 +00:00
|
|
|
int av_unused tmp, tmp2;
|
|
|
|
int samples, size;
|
2015-02-02 01:39:00 +00:00
|
|
|
int64_t pos = avio_tell(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
unsigned dts;
|
2010-03-02 21:32:29 +00:00
|
|
|
int ret;
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
dts = avio_rb32(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
st->codec->sample_rate = avio_rb32(s->pb);
|
2013-09-19 14:02:36 +00:00
|
|
|
if (st->codec->sample_rate <= 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Bad sample rate\n");
|
2013-01-29 16:13:45 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
samples = avio_rb32(s->pb);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb);
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "packet num %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2012-01-25 11:25:11 +00:00
|
|
|
tmp = avio_rb16(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_r8(s->pb); // major version
|
|
|
|
tmp2 = avio_r8(s->pb); // minor version
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "version %d.%d\n", tmp, tmp2);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
tmp = avio_rb32(s->pb); // unknown
|
2011-01-29 16:46:18 +00:00
|
|
|
av_dlog(s, "unknown %d\n", tmp);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
2011-03-03 19:11:45 +00:00
|
|
|
size = atom->size - 8 - (avio_tell(s->pb) - pos);
|
2009-01-20 07:42:14 +00:00
|
|
|
if (size < 0)
|
|
|
|
return -1;
|
2010-03-02 21:32:29 +00:00
|
|
|
ret = av_get_packet(s->pb, pkt, size);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "error reading audio packet\n");
|
|
|
|
return ret;
|
2009-01-20 07:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkt->stream_index = 1;
|
|
|
|
pkt->dts = dts;
|
2013-01-29 15:57:22 +00:00
|
|
|
if (st->codec->sample_rate)
|
|
|
|
pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
|
2011-05-29 19:07:35 +00:00
|
|
|
av_dlog(s, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n",
|
2009-01-20 07:42:14 +00:00
|
|
|
pkt->dts, pkt->duration, samples, st->codec->sample_rate);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
Atom atom;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
while (!err) {
|
|
|
|
if (read_atom(s, &atom) < 0) {
|
|
|
|
err = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (atom.tag) {
|
|
|
|
case MKTAG('R','E','D','V'):
|
|
|
|
if (s->streams[0]->discard == AVDISCARD_ALL)
|
|
|
|
goto skip;
|
|
|
|
if (!(err = r3d_read_redv(s, pkt, &atom)))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case MKTAG('R','E','D','A'):
|
|
|
|
if (s->nb_streams < 2)
|
|
|
|
return -1;
|
|
|
|
if (s->streams[1]->discard == AVDISCARD_ALL)
|
|
|
|
goto skip;
|
|
|
|
if (!(err = r3d_read_reda(s, pkt, &atom)))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skip:
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(s->pb, atom.size-8);
|
2009-01-20 07:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
if (AV_RL32(p->buf + 4) == MKTAG('R','E','D','1'))
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
|
|
|
|
{
|
|
|
|
AVStream *st = s->streams[0]; // video stream
|
|
|
|
R3DContext *r3d = s->priv_data;
|
|
|
|
int frame_num;
|
|
|
|
|
2012-06-26 11:10:01 +00:00
|
|
|
if (!st->avg_frame_rate.num)
|
2009-01-20 07:42:14 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-03-02 13:08:11 +00:00
|
|
|
frame_num = av_rescale_q(sample_time, st->time_base,
|
2012-08-05 21:25:27 +00:00
|
|
|
av_inv_q(st->avg_frame_rate));
|
2011-05-31 19:23:45 +00:00
|
|
|
av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
|
|
|
|
frame_num, sample_time);
|
2009-01-20 07:42:14 +00:00
|
|
|
|
|
|
|
if (frame_num < r3d->video_offsets_count) {
|
2011-09-14 17:32:29 +00:00
|
|
|
if (avio_seek(s->pb, r3d->video_offsets_count, SEEK_SET) < 0)
|
|
|
|
return -1;
|
2009-01-20 07:42:14 +00:00
|
|
|
} else {
|
|
|
|
av_log(s, AV_LOG_ERROR, "could not seek to frame %d\n", frame_num);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r3d_close(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
R3DContext *r3d = s->priv_data;
|
|
|
|
|
|
|
|
av_freep(&r3d->video_offsets);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:03:28 +00:00
|
|
|
AVInputFormat ff_r3d_demuxer = {
|
2011-07-16 20:18:12 +00:00
|
|
|
.name = "r3d",
|
2012-07-24 21:51:41 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("REDCODE R3D"),
|
2011-07-16 20:18:12 +00:00
|
|
|
.priv_data_size = sizeof(R3DContext),
|
|
|
|
.read_probe = r3d_probe,
|
|
|
|
.read_header = r3d_read_header,
|
|
|
|
.read_packet = r3d_read_packet,
|
|
|
|
.read_close = r3d_close,
|
|
|
|
.read_seek = r3d_seek,
|
2009-01-20 07:42:14 +00:00
|
|
|
};
|