FFmpeg  4.4.6
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 "wv.h"
28 
29 typedef struct WvMuxContext {
31 } WvMuxContext;
32 
34 {
35  if (ctx->nb_streams > 1 ||
37  av_log(ctx, AV_LOG_ERROR, "This muxer only supports a single WavPack stream.\n");
38  return AVERROR(EINVAL);
39  }
40 
41  return 0;
42 }
43 
45 {
48  int ret;
49 
50  if (pkt->size < WV_HEADER_SIZE ||
51  (ret = ff_wv_parse_header(&header, pkt->data)) < 0) {
52  av_log(ctx, AV_LOG_ERROR, "Invalid WavPack packet.\n");
53  return AVERROR(EINVAL);
54  }
55  s->samples += header.samples;
56 
58 
59  return 0;
60 }
61 
63 {
65 
66  /* update total number of samples in the first block */
67  if ((ctx->pb->seekable & AVIO_SEEKABLE_NORMAL) && s->samples &&
68  s->samples < UINT32_MAX) {
70  avio_seek(ctx->pb, 12, SEEK_SET);
71  avio_wl32(ctx->pb, s->samples);
72  avio_seek(ctx->pb, pos, SEEK_SET);
73  }
74 
76  return 0;
77 }
78 
80  .name = "wv",
81  .long_name = NULL_IF_CONFIG_SMALL("raw WavPack"),
82  .mime_type = "audio/x-wavpack",
83  .extensions = "wv",
84  .priv_data_size = sizeof(WvMuxContext),
85  .audio_codec = AV_CODEC_ID_WAVPACK,
86  .video_codec = AV_CODEC_ID_NONE,
91 };
int ff_ape_write_tag(AVFormatContext *s)
Write an APE tag into a file.
Definition: apetag.c:186
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
Main libavformat public API header.
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:462
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:253
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:375
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:225
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
long long int64_t
Definition: coverity.c:34
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:730
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346
@ AV_CODEC_ID_NONE
Definition: codec_id.h:47
@ AV_CODEC_ID_WAVPACK
Definition: codec_id.h:449
#define AVERROR(e)
Definition: error.h:43
#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:117
static const uint8_t header[24]
Definition: sdr2.c:67
unsigned int pos
Definition: spdifenc.c:412
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
Format I/O context.
Definition: avformat.h:1232
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1288
AVIOContext * pb
I/O context.
Definition: avformat.h:1274
void * priv_data
Format private data.
Definition: avformat.h:1260
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1300
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
const char * name
Definition: avformat.h:491
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1038
Definition: wv.h:34
int64_t samples
Definition: wvenc.c:30
#define av_log(a,...)
AVPacket * pkt
Definition: movenc.c:59
AVFormatContext * ctx
Definition: movenc.c:48
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
#define WV_HEADER_SIZE
Definition: wavpack.h:30
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
Definition: wv.c:29
static av_cold int wv_write_header(AVFormatContext *ctx)
Definition: wvenc.c:33
AVOutputFormat ff_wv_muxer
Definition: wvenc.c:79
static int wv_write_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: wvenc.c:44
static av_cold int wv_write_trailer(AVFormatContext *ctx)
Definition: wvenc.c:62