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 "rawenc.h"
26 #include "riff.h"
27 #include "rso.h"
28 
30 {
31  AVIOContext *pb = s->pb;
32  AVCodecParameters *par = s->streams[0]->codecpar;
33 
34  if (!par->codec_tag)
35  return AVERROR_INVALIDDATA;
36 
37  if (par->channels != 1) {
38  av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
39  return AVERROR_INVALIDDATA;
40  }
41 
42  if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
43  av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
44  return AVERROR_INVALIDDATA;
45  }
46 
47  /* XXX: find legal sample rates (if any) */
48  if (par->sample_rate >= 1u<<16) {
49  av_log(s, AV_LOG_ERROR, "Sample rate must be < 65536\n");
50  return AVERROR_INVALIDDATA;
51  }
52 
53  if (par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
54  avpriv_report_missing_feature(s, "ADPCM in RSO");
55  return AVERROR_PATCHWELCOME;
56  }
57 
58  /* format header */
59  avio_wb16(pb, par->codec_tag); /* codec ID */
60  avio_wb16(pb, 0); /* data size, will be written at EOF */
61  avio_wb16(pb, par->sample_rate);
62  avio_wb16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */
63 
64  return 0;
65 }
66 
68 {
69  AVIOContext *pb = s->pb;
70  int64_t file_size;
71  uint16_t coded_file_size;
72 
73  file_size = avio_tell(pb);
74 
75  if (file_size < 0)
76  return file_size;
77 
78  if (file_size > 0xffff + RSO_HEADER_SIZE) {
80  "Output file is too big (%"PRId64" bytes >= 64kB)\n", file_size);
81  coded_file_size = 0xffff;
82  } else {
83  coded_file_size = file_size - RSO_HEADER_SIZE;
84  }
85 
86  /* update file size */
87  avio_seek(pb, 2, SEEK_SET);
88  avio_wb16(pb, coded_file_size);
89  avio_seek(pb, file_size, SEEK_SET);
90 
91  return 0;
92 }
93 
95  .name = "rso",
96  .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO"),
97  .extensions = "rso",
98  .audio_codec = AV_CODEC_ID_PCM_U8,
99  .video_codec = AV_CODEC_ID_NONE,
100  .write_header = rso_write_header,
101  .write_packet = ff_raw_write_packet,
102  .write_trailer = rso_write_trailer,
103  .codec_tag = (const AVCodecTag* const []){ff_codec_rso_tags, 0},
104  .flags = AVFMT_NOTIMESTAMPS,
105 };
Bytestream IO Context.
Definition: avio.h:161
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:253
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
Format I/O context.
Definition: avformat.h:1355
#define RSO_HEADER_SIZE
Definition: rso.h:27
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1423
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
static int rso_write_header(AVFormatContext *s)
Definition: rsoenc.c:29
const char * name
Definition: avformat.h:500
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
AVOutputFormat ff_rso_muxer
Definition: rsoenc.c:94
#define s(width, name)
Definition: cbs_vp9.c:257
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawenc.c:29
const AVCodecTag ff_codec_rso_tags[]
Definition: rso.c:26
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:462
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
AVIOContext * pb
I/O context.
Definition: avformat.h:1397
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:465
int sample_rate
Audio only.
Definition: codec_par.h:170
Main libavformat public API header.
int channels
Audio only.
Definition: codec_par.h:166
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1027
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:64
static int rso_write_trailer(AVFormatContext *s)
Definition: rsoenc.c:67