2002-10-08 17:58:36 +00:00
|
|
|
/*
|
|
|
|
* Raw DV format
|
|
|
|
* Copyright (c) 2002 Fabrice Bellard.
|
|
|
|
*
|
|
|
|
* This library 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 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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 this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include "avformat.h"
|
|
|
|
|
|
|
|
#define NTSC_FRAME_SIZE 120000
|
|
|
|
#define PAL_FRAME_SIZE 144000
|
|
|
|
|
|
|
|
typedef struct DVDemuxContext {
|
2003-01-27 09:21:30 +00:00
|
|
|
int is_audio;
|
|
|
|
uint8_t buf[PAL_FRAME_SIZE];
|
|
|
|
int size;
|
2002-10-08 17:58:36 +00:00
|
|
|
} DVDemuxContext;
|
|
|
|
|
|
|
|
/* raw input */
|
|
|
|
static int dv_read_header(AVFormatContext *s,
|
|
|
|
AVFormatParameters *ap)
|
|
|
|
{
|
2003-01-27 09:21:30 +00:00
|
|
|
AVStream *vst, *ast;
|
|
|
|
DVDemuxContext *c = s->priv_data;
|
2002-10-08 17:58:36 +00:00
|
|
|
|
|
|
|
vst = av_new_stream(s, 0);
|
|
|
|
if (!vst)
|
|
|
|
return AVERROR_NOMEM;
|
|
|
|
vst->codec.codec_type = CODEC_TYPE_VIDEO;
|
|
|
|
vst->codec.codec_id = CODEC_ID_DVVIDEO;
|
|
|
|
|
2003-01-27 09:21:30 +00:00
|
|
|
|
2002-10-08 17:58:36 +00:00
|
|
|
ast = av_new_stream(s, 1);
|
|
|
|
if (!ast)
|
|
|
|
return AVERROR_NOMEM;
|
|
|
|
|
|
|
|
ast->codec.codec_type = CODEC_TYPE_AUDIO;
|
|
|
|
ast->codec.codec_id = CODEC_ID_DVAUDIO;
|
2003-01-27 09:21:30 +00:00
|
|
|
c->is_audio = 0;
|
|
|
|
|
2002-10-08 17:58:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-06 22:34:55 +00:00
|
|
|
static void __destruct_pkt(struct AVPacket *pkt)
|
|
|
|
{
|
|
|
|
pkt->data = NULL; pkt->size = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-11 09:07:32 +00:00
|
|
|
static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
2002-10-08 17:58:36 +00:00
|
|
|
{
|
2003-01-27 09:21:30 +00:00
|
|
|
int ret, dsf;
|
|
|
|
DVDemuxContext *c = s->priv_data;
|
2002-10-08 17:58:36 +00:00
|
|
|
|
2003-01-27 09:21:30 +00:00
|
|
|
if (!c->is_audio) {
|
|
|
|
ret = get_buffer(&s->pb, c->buf, 4);
|
|
|
|
if (ret <= 0)
|
|
|
|
return -EIO;
|
|
|
|
dsf = c->buf[3] & 0x80;
|
|
|
|
if (!dsf)
|
|
|
|
c->size = NTSC_FRAME_SIZE;
|
|
|
|
else
|
|
|
|
c->size = PAL_FRAME_SIZE;
|
|
|
|
|
|
|
|
ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
|
|
|
|
if (ret <= 0)
|
|
|
|
return -EIO;
|
|
|
|
}
|
2002-10-08 17:58:36 +00:00
|
|
|
|
2003-02-06 22:34:55 +00:00
|
|
|
av_init_packet(pkt);
|
|
|
|
pkt->destruct = __destruct_pkt;
|
|
|
|
pkt->data = c->buf;
|
|
|
|
pkt->size = c->size;
|
2003-01-27 09:21:30 +00:00
|
|
|
pkt->stream_index = c->is_audio;
|
2003-04-23 02:04:40 +00:00
|
|
|
pkt->flags |= PKT_FLAG_KEY;
|
2003-02-06 22:34:55 +00:00
|
|
|
|
2003-01-27 09:21:30 +00:00
|
|
|
c->is_audio = !c->is_audio;
|
2003-02-06 22:34:55 +00:00
|
|
|
return c->size;
|
2002-10-08 17:58:36 +00:00
|
|
|
}
|
|
|
|
|
2002-11-11 09:07:32 +00:00
|
|
|
static int dv_read_close(AVFormatContext *s)
|
2002-10-08 17:58:36 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-11 09:07:32 +00:00
|
|
|
static AVInputFormat dv_iformat = {
|
2002-10-08 17:58:36 +00:00
|
|
|
"dv",
|
|
|
|
"DV video format",
|
|
|
|
sizeof(DVDemuxContext),
|
|
|
|
NULL,
|
|
|
|
dv_read_header,
|
|
|
|
dv_read_packet,
|
|
|
|
dv_read_close,
|
2002-10-11 07:23:35 +00:00
|
|
|
.extensions = "dv",
|
2002-10-08 17:58:36 +00:00
|
|
|
};
|
|
|
|
|
2003-04-08 09:56:19 +00:00
|
|
|
|
2002-10-08 17:58:36 +00:00
|
|
|
int dv_write_header(struct AVFormatContext *s)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dv_write_packet(struct AVFormatContext *s,
|
|
|
|
int stream_index,
|
|
|
|
unsigned char *buf, int size, int force_pts)
|
|
|
|
{
|
|
|
|
put_buffer(&s->pb, buf, size);
|
|
|
|
put_flush_packet(&s->pb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dv_write_trailer(struct AVFormatContext *s)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVOutputFormat dv_oformat = {
|
|
|
|
"dv",
|
|
|
|
"DV video format",
|
|
|
|
NULL,
|
|
|
|
"dv",
|
|
|
|
0,
|
|
|
|
CODEC_ID_DVVIDEO,
|
|
|
|
CODEC_ID_DVAUDIO,
|
|
|
|
dv_write_header,
|
|
|
|
dv_write_packet,
|
|
|
|
dv_write_trailer,
|
|
|
|
};
|
|
|
|
|
|
|
|
int dv_init(void)
|
|
|
|
{
|
|
|
|
av_register_input_format(&dv_iformat);
|
2003-04-08 09:56:19 +00:00
|
|
|
av_register_output_format(&dv_oformat);
|
2002-10-08 17:58:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|