1 /*
2 * Copyright (c) 2011 Anton Khirnov <anton@khirnov.net>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * libcdio CD grabbing
24 */
25
27
28 #if HAVE_CDIO_PARANOIA_H
29 #include <cdio/cdda.h>
30 #include <cdio/paranoia.h>
31 #elif HAVE_CDIO_PARANOIA_PARANOIA_H
32 #include <cdio/paranoia/cdda.h>
33 #include <cdio/paranoia/paranoia.h>
34 #endif
35
39
42
48
49 /* private options */
53
55 {
58 int ret, i;
60
63 s->
drive = cdio_cddap_identify(ctx->
filename, CDDA_MESSAGE_LOGIT, &err);
67 }
68 if (err) {
70 free(err);
71 }
72 if ((ret = cdio_cddap_open(s->
drive)) < 0 || !s->
drive->opened) {
75 }
76
77 cdio_cddap_verbose_set(s->
drive, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT);
80
85 }
87
89 if (s->
drive->bigendianp)
91 else
95 if (s->
drive->audio_last_sector != CDIO_INVALID_LSN &&
96 s->
drive->audio_first_sector != CDIO_INVALID_LSN)
98 else if (s->
drive->tracks)
101
102 for (i = 0; i < s->
drive->tracks; i++) {
103 char title[16];
104 snprintf(title,
sizeof(title),
"track %02d", s->
drive->disc_toc[i].bTrack);
106 s->
drive->disc_toc[i+1].dwStartSector, title);
107 }
108
110
111 return 0;
112 }
113
115 {
117 int ret;
120
123
125 if (!buf)
127
128 if (err = cdio_cddap_errors(s->
drive)) {
130 free(err);
132 }
133 if (err = cdio_cddap_messages(s->
drive)) {
135 free(err);
137 }
138
140 return ret;
141 memcpy(pkt->
data, buf, CDIO_CD_FRAMESIZE_RAW);
142 return 0;
143 }
144
146 {
149 cdio_cddap_close(s->
drive);
150 return 0;
151 }
152
155 {
158
159 cdio_paranoia_seek(s->
paranoia, timestamp, SEEK_SET);
161 return 0;
162 }
163
164 #define OFFSET(x) offsetof(CDIOContext, x)
165 #define DEC AV_OPT_FLAG_DECODING_PARAM
168 {
"paranoia_mode",
"set error recovery mode",
OFFSET(paranoia_mode),
AV_OPT_TYPE_FLAGS, { .i64 = PARANOIA_MODE_DISABLE }, INT_MIN, INT_MAX,
DEC,
"paranoia_mode" },
169 {
"disable",
"apply no fixups", 0,
AV_OPT_TYPE_CONST, { .i64 = PARANOIA_MODE_DISABLE }, 0, 0,
DEC,
"paranoia_mode" },
170 {
"verify",
"verify data integrity in overlap area", 0,
AV_OPT_TYPE_CONST, { .i64 = PARANOIA_MODE_VERIFY }, 0, 0,
DEC,
"paranoia_mode" },
171 {
"overlap",
"perform overlapped reads", 0,
AV_OPT_TYPE_CONST, { .i64 = PARANOIA_MODE_OVERLAP }, 0, 0,
DEC,
"paranoia_mode" },
172 {
"neverskip",
"do not skip failed reads", 0,
AV_OPT_TYPE_CONST, { .i64 = PARANOIA_MODE_NEVERSKIP }, 0, 0,
DEC,
"paranoia_mode" },
173 {
"full",
"apply all recovery modes", 0,
AV_OPT_TYPE_CONST, { .i64 = PARANOIA_MODE_FULL }, 0, 0,
DEC,
"paranoia_mode" },
175 };
176
183 };
184
193 .priv_class = &libcdio_class,
194 };
#define LIBAVUTIL_VERSION_INT
memory handling functions
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVCodecContext * codec
Codec context associated with this stream.
char filename[1024]
input or output filename
static av_cold int read_header(AVFormatContext *ctx)
enum AVMediaType codec_type
int sample_rate
samples per second
static const AVOption options[]
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Describe the class of an AVClass context structure.
int64_t duration
Decoding: duration of the stream, in stream time base.
cdrom_paranoia_t * paranoia
int channels
number of audio channels
void * priv_data
Format private data.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.
AVInputFormat ff_libcdio_demuxer
static const AVClass libcdio_class