FFmpeg
Loading...
Searching...
No Matches
bmv.c
Go to the documentation of this file.
1/*
2 * Discworld II BMV demuxer
3 * Copyright (c) 2011 Konstantin Shishkov
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
23#include "libavutil/mem.h"
24#include "avformat.h"
25#include "avio_internal.h"
26#include "demux.h"
27#include "internal.h"
28
37
38typedef struct BMVContext {
39 uint8_t *packet;
40 int size;
44
46{
47 AVStream *st, *ast;
48 BMVContext *c = s->priv_data;
49
50 st = avformat_new_stream(s, 0);
51 if (!st)
52 return AVERROR(ENOMEM);
55 st->codecpar->width = 640;
56 st->codecpar->height = 429;
58 avpriv_set_pts_info(st, 16, 1, 12);
59 ast = avformat_new_stream(s, 0);
60 if (!ast)
61 return AVERROR(ENOMEM);
65 ast->codecpar->sample_rate = 22050;
66 avpriv_set_pts_info(ast, 16, 1, 22050);
67
68 c->get_next = 1;
69 c->audio_pos = 0;
70 return 0;
71}
72
74{
75 BMVContext *c = s->priv_data;
76 int type, err;
77
78 while (c->get_next) {
79 if (s->pb->eof_reached)
80 return AVERROR_EOF;
81 type = avio_r8(s->pb);
82 if (type == BMV_NOP)
83 continue;
84 if (type == BMV_END)
85 return AVERROR_EOF;
86 c->size = avio_rl24(s->pb);
87 if (!c->size)
89 if ((err = av_reallocp(&c->packet, c->size + 1)) < 0)
90 return err;
91 c->packet[0] = type;
92 if ((err = ffio_read_size(s->pb, c->packet + 1, c->size)) < 0)
93 return err;
94 if (type & BMV_AUDIO) {
95 int audio_size = c->packet[1] * 65 + 1;
96 if (audio_size >= c->size) {
97 av_log(s, AV_LOG_ERROR, "Reported audio size %d is bigger than packet size (%d)\n",
98 audio_size, c->size);
100 }
101 if ((err = av_new_packet(pkt, audio_size)) < 0)
102 return err;
103 memcpy(pkt->data, c->packet + 1, pkt->size);
104 pkt->stream_index = 1;
105 pkt->pts = c->audio_pos;
106 pkt->duration = c->packet[1] * 32;
107 c->audio_pos += pkt->duration;
108 c->get_next = 0;
109 return pkt->size;
110 } else
111 break;
112 }
113 if ((err = av_new_packet(pkt, c->size + 1)) < 0)
114 return err;
115 pkt->stream_index = 0;
116 c->get_next = 1;
117 memcpy(pkt->data, c->packet, pkt->size);
118 return pkt->size;
119}
120
122{
123 BMVContext *c = s->priv_data;
124
125 av_freep(&c->packet);
126
127 return 0;
128}
129
131 .p.name = "bmv",
132 .p.long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV"),
133 .p.extensions = "bmv",
134 .priv_data_size = sizeof(BMVContext),
138};
const FFInputFormat ff_bmv_demuxer
Definition bmv.c:130
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
unsigned int avio_rl24(AVIOContext *s)
Definition aviobuf.c:725
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:665
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int bmv_read_header(AVFormatContext *s)
Definition bmv.c:45
static int bmv_read_close(AVFormatContext *s)
Definition bmv.c:121
static int bmv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition bmv.c:73
BMVFlags
Definition bmvvideo.c:30
@ BMV_END
Definition bmvvideo.c:32
@ BMV_INTRA
Definition bmvvideo.c:34
@ BMV_NOP
Definition bmvvideo.c:31
@ BMV_AUDIO
Definition bmvvideo.c:39
@ BMV_DELTA
Definition bmvvideo.c:33
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_BMV_VIDEO
Definition codec_id.h:204
@ AV_CODEC_ID_BMV_AUDIO
Definition codec_id.h:509
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_CHANNEL_LAYOUT_STEREO
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition mem.c:188
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
cl_device_type type
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
Memory handling functions.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
An AVChannelLayout holds information about the channel layout of audio data.
int height
The height of the video frame in pixels.
Definition codec_par.h:150
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int get_next
Definition bmv.c:41
int size
Definition bmv.c:40
int64_t audio_pos
Definition bmv.c:42
uint8_t * packet
Definition bmv.c:39
#define av_freep(p)
#define av_log(a,...)
static double c[64]