c9484148 |
/*
* Gremlin Digital Video demuxer
* Copyright (c) 2017 Paul B Mahol
*
* 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"
#include "avformat.h"
#include "avio.h"
#include "internal.h"
typedef struct GDVContext {
int is_first_video;
int is_audio;
int audio_size;
int audio_stream_index;
int video_stream_index;
unsigned pal[256];
} GDVContext;
|
4d681269 |
uint16_t id;
uint16_t width;
uint16_t height;
} FixedSize[] = {
{ 0, 320, 200},
{ 1, 640, 200},
{ 2, 320, 167},
{ 3, 320, 180},
{ 4, 320, 400},
{ 5, 320, 170},
{ 6, 160, 85},
{ 7, 160, 83},
{ 8, 160, 90},
{ 9, 280, 128},
{10, 320, 240},
{11, 320, 201},
{16, 640, 400},
{17, 640, 200},
{18, 640, 180},
{19, 640, 167},
{20, 640, 170},
{21, 320, 240}
};
|
c9484148 |
}
}
gdv->is_first_video = 1;
return 0;
}
static int gdv_read_packet(AVFormatContext *ctx, AVPacket *pkt)
{
GDVContext *gdv = ctx->priv_data;
AVIOContext *pb = ctx->pb;
int ret;
if (avio_feof(pb))
return pb->error ? pb->error : AVERROR_EOF;
if (gdv->audio_size && gdv->is_audio) {
ret = av_get_packet(pb, pkt, gdv->audio_size);
if (ret < 0)
return ret;
pkt->stream_index = 1;
gdv->is_audio = 0;
} else {
uint8_t *pal;
if (avio_rl16(pb) != 0x1305)
return AVERROR_INVALIDDATA;
ret = av_get_packet(pb, pkt, 4 + avio_rl16(pb));
if (ret < 0)
return ret;
pkt->stream_index = 0;
gdv->is_audio = 1;
if (gdv->is_first_video) {
pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
AVPALETTE_SIZE);
if (!pal) {
return AVERROR(ENOMEM);
}
memcpy(pal, gdv->pal, AVPALETTE_SIZE);
pkt->flags |= AV_PKT_FLAG_KEY;
gdv->is_first_video = 0;
}
}
return 0;
}
AVInputFormat ff_gdv_demuxer = {
.name = "gdv",
.long_name = NULL_IF_CONFIG_SMALL("Gremlin Digital Video"),
.priv_data_size = sizeof(GDVContext),
.read_probe = gdv_read_probe,
.read_header = gdv_read_header,
.read_packet = gdv_read_packet,
}; |