FFmpeg
wvenc.c
Go to the documentation of this file.
1 /*
2  * WavPack muxer
3  * Copyright (c) 2013 Konstantin Shishkov <kostya.shishkov@gmail.com>
4  * Copyright (c) 2012 Paul B Mahol
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 "libavutil/attributes.h"
24 
25 #include "apetag.h"
26 #include "avformat.h"
27 #include "mux.h"
28 #include "wv.h"
29 
30 typedef struct WvMuxContext {
31  int64_t samples;
32 } WvMuxContext;
33 
35 {
36  if (ctx->nb_streams > 1 ||
38  av_log(ctx, AV_LOG_ERROR, "This muxer only supports a single WavPack stream.\n");
39  return AVERROR(EINVAL);
40  }
41 
42  return 0;
43 }
44 
46 {
49  int ret;
50 
51  if (pkt->size < WV_HEADER_SIZE ||
52  (ret = ff_wv_parse_header(&header, pkt->data)) < 0) {
53  av_log(ctx, AV_LOG_ERROR, "Invalid WavPack packet.\n");
54  return AVERROR(EINVAL);
55  }
56  s->samples += header.samples;
57 
59 
60  return 0;
61 }
62 
64 {
66 
67  /* update total number of samples in the first block */
68  if ((ctx->pb->seekable & AVIO_SEEKABLE_NORMAL) && s->samples &&
69  s->samples < UINT32_MAX) {
70  int64_t pos = avio_tell(ctx->pb);
71  avio_seek(ctx->pb, 12, SEEK_SET);
72  avio_wl32(ctx->pb, s->samples);
73  avio_seek(ctx->pb, pos, SEEK_SET);
74  }
75 
77  return 0;
78 }
79 
81  .p.name = "wv",
82  .p.long_name = NULL_IF_CONFIG_SMALL("raw WavPack"),
83  .p.mime_type = "audio/x-wavpack",
84  .p.extensions = "wv",
85  .priv_data_size = sizeof(WvMuxContext),
86  .p.audio_codec = AV_CODEC_ID_WAVPACK,
87  .p.video_codec = AV_CODEC_ID_NONE,
88  .init = wv_init,
89  .write_packet = wv_write_packet,
90  .write_trailer = wv_write_trailer,
91  .p.flags = AVFMT_NOTIMESTAMPS,
92 };
AVOutputFormat::name
const char * name
Definition: avformat.h:511
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:480
apetag.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1183
AVPacket::data
uint8_t * data
Definition: packet.h:491
WvMuxContext::samples
int64_t samples
Definition: wvenc.c:31
WvHeader
Definition: wv.h:34
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:36
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:513
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
wv_write_trailer
static av_cold int wv_write_trailer(AVFormatContext *ctx)
Definition: wvenc.c:63
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_ape_write_tag
int ff_ape_write_tag(AVFormatContext *s)
Write an APE tag into a file.
Definition: apetag.c:176
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
WV_HEADER_SIZE
#define WV_HEADER_SIZE
Definition: wavpack.h:33
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1157
FFOutputFormat
Definition: mux.h:32
WvMuxContext
Definition: wvenc.c:30
wv_init
static av_cold int wv_init(AVFormatContext *ctx)
Definition: wvenc.c:34
ff_wv_parse_header
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
Definition: wv.c:30
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1171
ff_wv_muxer
const FFOutputFormat ff_wv_muxer
Definition: wvenc.c:80
AVPacket::size
int size
Definition: packet.h:492
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:106
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:271
header
static const uint8_t header[24]
Definition: sdr2.c:67
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:248
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:404
attributes.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
ret
ret
Definition: filter_design.txt:187
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:278
pos
unsigned int pos
Definition: spdifenc.c:413
avformat.h
wv.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
wv_write_packet
static int wv_write_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: wvenc.c:45
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:468
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_CODEC_ID_WAVPACK
@ AV_CODEC_ID_WAVPACK
Definition: codec_id.h:467
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1143
mux.h