* 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.
*
* 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.
*
* 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
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Sega FILM (.cpk) file demuxer
* by Mike Melanson (melanson@pcisys.net)
* For more information regarding the Sega FILM file format, visit:
* http://www.pcisys.net/~melanson/codecs/
*/
* Sega FILM (.cpk) file demuxer
* by Mike Melanson (melanson@pcisys.net)
* For more information regarding the Sega FILM file format, visit:
* http://www.pcisys.net/~melanson/codecs/
*/
#include "avformat.h"
#define FILM_TAG MKBETAG('F', 'I', 'L', 'M')
#include "avformat.h"
#define FILM_TAG MKBETAG('F', 'I', 'L', 'M')
data_offset = AV_RB32(&scratch[4]);
film->version = AV_RB32(&scratch[8]);
/* load the FDSC chunk */
if (film->version == 0) {
/* special case for Lemmings .film files; 20-byte header */
data_offset = AV_RB32(&scratch[4]);
film->version = AV_RB32(&scratch[8]);
/* load the FDSC chunk */
if (film->version == 0) {
/* special case for Lemmings .film files; 20-byte header */
/* make some assumptions about the audio parameters */
film->audio_type = CODEC_ID_PCM_S8;
film->audio_samplerate = 22050;
/* make some assumptions about the audio parameters */
film->audio_type = CODEC_ID_PCM_S8;
film->audio_samplerate = 22050;
- if (get_buffer(pb, scratch, 32) != 32)
- return AVERROR_IO;
- film->audio_samplerate = AV_RB16(&scratch[24]);;
+ if (avio_read(pb, scratch, 32) != 32)
+ return AVERROR(EIO);
+ film->audio_samplerate = AV_RB16(&scratch[24]);
film->audio_channels = scratch[21];
film->audio_bits = scratch[22];
if (film->audio_bits == 8)
film->audio_channels = scratch[21];
film->audio_bits = scratch[22];
if (film->audio_bits == 8)
/* initialize the decoder streams */
if (film->video_type) {
st = av_new_stream(s, 0);
if (!st)
/* initialize the decoder streams */
if (film->video_type) {
st = av_new_stream(s, 0);
if (!st)
st->codec->codec_id = film->video_type;
st->codec->codec_tag = 0; /* no fourcc */
st->codec->width = AV_RB32(&scratch[16]);
st->codec->codec_id = film->video_type;
st->codec->codec_tag = 0; /* no fourcc */
st->codec->width = AV_RB32(&scratch[16]);
st->codec->codec_id = film->audio_type;
st->codec->codec_tag = 1;
st->codec->channels = film->audio_channels;
st->codec->codec_id = film->audio_type;
st->codec->codec_tag = 1;
st->codec->channels = film->audio_channels;
st->codec->sample_rate = film->audio_samplerate;
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
st->codec->sample_rate = film->audio_samplerate;
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
if (AV_RB32(&scratch[0]) != STAB_TAG)
return AVERROR_INVALIDDATA;
film->base_clock = AV_RB32(&scratch[8]);
film->sample_count = AV_RB32(&scratch[12]);
if (AV_RB32(&scratch[0]) != STAB_TAG)
return AVERROR_INVALIDDATA;
film->base_clock = AV_RB32(&scratch[8]);
film->sample_count = AV_RB32(&scratch[12]);
for(i=0; i<s->nb_streams; i++)
av_set_pts_info(s->streams[i], 33, 1, film->base_clock);
for(i=0; i<s->nb_streams; i++)
av_set_pts_info(s->streams[i], 33, 1, film->base_clock);
audio_frame_counter = 0;
for (i = 0; i < film->sample_count; i++) {
/* load the next sample record and transfer it to an internal struct */
audio_frame_counter = 0;
for (i = 0; i < film->sample_count; i++) {
/* load the next sample record and transfer it to an internal struct */
sample = &film->sample_table[film->current_sample];
/* position the stream (will probably be there anyway) */
sample = &film->sample_table[film->current_sample];
/* position the stream (will probably be there anyway) */
/* do a special song and dance when loading FILM Cinepak chunks */
if ((sample->stream == film->video_stream_index) &&
(film->video_type == CODEC_ID_CINEPAK)) {
/* do a special song and dance when loading FILM Cinepak chunks */
if ((sample->stream == film->video_stream_index) &&
(film->video_type == CODEC_ID_CINEPAK)) {
- return AVERROR_NOMEM;
- get_buffer(pb, pkt->data, sample->sample_size);
+ return AVERROR(ENOMEM);
+ avio_read(pb, pkt->data, sample->sample_size);
} else if ((sample->stream == film->audio_stream_index) &&
(film->audio_channels == 2)) {
/* stereo PCM needs to be interleaved */
if (av_new_packet(pkt, sample->sample_size))
} else if ((sample->stream == film->audio_stream_index) &&
(film->audio_channels == 2)) {
/* stereo PCM needs to be interleaved */
if (av_new_packet(pkt, sample->sample_size))
/* make sure the interleave buffer is large enough */
if (sample->sample_size > film->stereo_buffer_size) {
/* make sure the interleave buffer is large enough */
if (sample->sample_size > film->stereo_buffer_size) {
- pkt->pos= url_ftell(pb);
- ret = get_buffer(pb, film->stereo_buffer, sample->sample_size);
+ pkt->pos= avio_tell(pb);
+ ret = avio_read(pb, film->stereo_buffer, sample->sample_size);
} else {
ret= av_get_packet(pb, pkt, sample->sample_size);
if (ret != sample->sample_size)
} else {
ret= av_get_packet(pb, pkt, sample->sample_size);
if (ret != sample->sample_size)