FFmpeg
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)
36  return AVERROR_INVALIDDATA;
37 
38  if (par->ch_layout.nb_channels != 1) {
39  av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
40  return AVERROR_INVALIDDATA;
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");
45  return AVERROR_INVALIDDATA;
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");
51  return AVERROR_INVALIDDATA;
52  }
53 
54  if (par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
55  avpriv_report_missing_feature(s, "ADPCM in RSO");
56  return AVERROR_PATCHWELCOME;
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 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:479
int64_t
long long int64_t
Definition: coverity.c:34
rso.h
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:328
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
rso_write_header
static int rso_write_header(AVFormatContext *s)
Definition: rsoenc.c:30
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
RSO_HEADER_SIZE
#define RSO_HEADER_SIZE
Definition: rso.h:27
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_rso_muxer
const FFOutputFormat ff_rso_muxer
Definition: rsoenc.c:95
ff_raw_write_packet
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawenc.c:31
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
internal.h
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
FFOutputFormat
Definition: mux.h:61
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
ff_rso_codec_tags_list
const AVCodecTag *const ff_rso_codec_tags_list[]
Definition: rso.c:32
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
rawenc.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
FF_OFMT_FLAG_MAX_ONE_OF_EACH
#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
rso_write_trailer
static int rso_write_trailer(AVFormatContext *s)
Definition: rsoenc.c:68
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
avformat.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:339
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AV_CODEC_ID_ADPCM_IMA_WAV
@ AV_CODEC_ID_ADPCM_IMA_WAV
Definition: codec_id.h:374
riff.h
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:443
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
mux.h