FFmpeg
Loading...
Searching...
No Matches
rsoenc.c
Go to the documentation of this file.
1/*
2 * RSO muxer
3 * Copyright (c) 2001 Fabrice Bellard (original AU code)
4 * Copyright (c) 2010 Rafael Carre
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "avformat.h"
24#include "internal.h"
25#include "mux.h"
26#include "rawenc.h"
27#include "riff.h"
28#include "rso.h"
29
31{
32 AVIOContext *pb = s->pb;
33 AVCodecParameters *par = s->streams[0]->codecpar;
34
35 if (!par->codec_tag)
37
38 if (par->ch_layout.nb_channels != 1) {
39 av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
41 }
42
43 if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
44 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
46 }
47
48 /* XXX: find legal sample rates (if any) */
49 if (par->sample_rate >= 1u<<16) {
50 av_log(s, AV_LOG_ERROR, "Sample rate must be < 65536\n");
52 }
53
55 avpriv_report_missing_feature(s, "ADPCM in RSO");
57 }
58
59 /* format header */
60 avio_wb16(pb, par->codec_tag); /* codec ID */
61 avio_wb16(pb, 0); /* data size, will be written at EOF */
62 avio_wb16(pb, par->sample_rate);
63 avio_wb16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */
64
65 return 0;
66}
67
69{
70 AVIOContext *pb = s->pb;
71 int64_t file_size;
72 uint16_t coded_file_size;
73
74 file_size = avio_tell(pb);
75
76 if (file_size < 0)
77 return file_size;
78
79 if (file_size > 0xffff + RSO_HEADER_SIZE) {
81 "Output file is too big (%"PRId64" bytes >= 64kB)\n", file_size);
82 coded_file_size = 0xffff;
83 } else {
84 coded_file_size = file_size - RSO_HEADER_SIZE;
85 }
86
87 /* update file size */
88 avio_seek(pb, 2, SEEK_SET);
89 avio_wb16(pb, coded_file_size);
90 avio_seek(pb, file_size, SEEK_SET);
91
92 return 0;
93}
94
96 .p.name = "rso",
97 .p.long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO"),
98 .p.extensions = "rso",
99 .p.audio_codec = AV_CODEC_ID_PCM_U8,
100 .p.video_codec = AV_CODEC_ID_NONE,
101 .p.subtitle_codec = AV_CODEC_ID_NONE,
102 .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH,
103 .write_header = rso_write_header,
104 .write_packet = ff_raw_write_packet,
105 .write_trailer = rso_write_trailer,
106 .p.codec_tag = ff_rso_codec_tags_list,
107 .p.flags = AVFMT_NOTIMESTAMPS,
108};
const FFOutputFormat ff_rso_muxer
Definition rsoenc.c:95
Main libavformat public API header.
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition avio.h:41
void avio_wb16(AVIOContext *s, unsigned int val)
Definition aviobuf.c:446
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
@ AV_CODEC_ID_PCM_U8
Definition codec_id.h:335
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_ADPCM_IMA_WAV
Definition codec_id.h:371
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition rawenc.c:31
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
Definition mux.h:50
internal header for RIFF based (de)muxers do NOT include this in end user applications
const AVCodecTag *const ff_rso_codec_tags_list[]
Definition rso.c:32
#define RSO_HEADER_SIZE
Definition rso.h:27
static int rso_write_header(AVFormatContext *s)
Definition rsoenc.c:30
static int rso_write_trailer(AVFormatContext *s)
Definition rsoenc.c:68
int nb_channels
Number of channels in this layout.
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
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
Bytestream IO Context.
Definition avio.h:160
#define av_log(a,...)