FFmpeg
bluray.c
Go to the documentation of this file.
1 /*
2  * BluRay (libbluray) protocol
3  *
4  * Copyright (c) 2012 Petri Hintukainen <phintuka <at> users.sourceforge.net>
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 <libbluray/bluray.h>
24 
25 #include "libavutil/avstring.h"
26 #include "libavformat/url.h"
27 #include "libavutil/opt.h"
28 
29 #define BLURAY_PROTO_PREFIX "bluray:"
30 #define MIN_PLAYLIST_LENGTH 180 /* 3 min */
31 
32 typedef struct {
33  const AVClass *class;
34 
35  BLURAY *bd;
36 
37  int playlist;
38  int angle;
39  int chapter;
40  /*int region;*/
42 
43 #define OFFSET(x) offsetof(BlurayContext, x)
44 static const AVOption options[] = {
45 {"playlist", "", OFFSET(playlist), AV_OPT_TYPE_INT, { .i64=-1 }, -1, 99999, AV_OPT_FLAG_DECODING_PARAM },
46 {"angle", "", OFFSET(angle), AV_OPT_TYPE_INT, { .i64=0 }, 0, 0xfe, AV_OPT_FLAG_DECODING_PARAM },
47 {"chapter", "", OFFSET(chapter), AV_OPT_TYPE_INT, { .i64=1 }, 1, 0xfffe, AV_OPT_FLAG_DECODING_PARAM },
48 /*{"region", "bluray player region code (1 = region A, 2 = region B, 4 = region C)", OFFSET(region), AV_OPT_TYPE_INT, { .i64=0 }, 0, 3, AV_OPT_FLAG_DECODING_PARAM },*/
49 {NULL}
50 };
51 
52 static const AVClass bluray_context_class = {
53  .class_name = "bluray",
54  .item_name = av_default_item_name,
55  .option = options,
56  .version = LIBAVUTIL_VERSION_INT,
57 };
58 
59 
61 {
62  BlurayContext *bd = h->priv_data;
63  const BLURAY_DISC_INFO *disc_info;
64 
65  disc_info = bd_get_disc_info(bd->bd);
66  if (!disc_info) {
67  av_log(h, AV_LOG_ERROR, "bd_get_disc_info() failed\n");
68  return -1;
69  }
70 
71  if (!disc_info->bluray_detected) {
72  av_log(h, AV_LOG_ERROR, "BluRay disc not detected\n");
73  return -1;
74  }
75 
76  /* AACS */
77  if (disc_info->aacs_detected && !disc_info->aacs_handled) {
78  if (!disc_info->libaacs_detected) {
80  "Media stream encrypted with AACS, install and configure libaacs\n");
81  } else {
82  av_log(h, AV_LOG_ERROR, "Your libaacs can't decrypt this media\n");
83  }
84  return -1;
85  }
86 
87  /* BD+ */
88  if (disc_info->bdplus_detected && !disc_info->bdplus_handled) {
89  /*
90  if (!disc_info->libbdplus_detected) {
91  av_log(h, AV_LOG_ERROR,
92  "Media stream encrypted with BD+, install and configure libbdplus");
93  } else {
94  */
95  av_log(h, AV_LOG_ERROR, "Unable to decrypt BD+ encrypted media\n");
96  /*}*/
97  return -1;
98  }
99 
100  return 0;
101 }
102 
104 {
105  BlurayContext *bd = h->priv_data;
106  if (bd->bd) {
107  bd_close(bd->bd);
108  }
109 
110  return 0;
111 }
112 
113 static int bluray_open(URLContext *h, const char *path, int flags)
114 {
115  BlurayContext *bd = h->priv_data;
116  int num_title_idx;
117  const char *diskname = path;
118 
119  av_strstart(path, BLURAY_PROTO_PREFIX, &diskname);
120 
121  bd->bd = bd_open(diskname, NULL);
122  if (!bd->bd) {
123  av_log(h, AV_LOG_ERROR, "bd_open() failed\n");
124  return AVERROR(EIO);
125  }
126 
127  /* check if disc can be played */
128  if (check_disc_info(h) < 0) {
129  return AVERROR(EIO);
130  }
131 
132  /* setup player registers */
133  /* region code has no effect without menus
134  if (bd->region > 0 && bd->region < 5) {
135  av_log(h, AV_LOG_INFO, "setting region code to %d (%c)\n", bd->region, 'A' + (bd->region - 1));
136  bd_set_player_setting(bd->bd, BLURAY_PLAYER_SETTING_REGION_CODE, bd->region);
137  }
138  */
139 
140  /* load title list */
141  num_title_idx = bd_get_titles(bd->bd, TITLES_RELEVANT, MIN_PLAYLIST_LENGTH);
142  av_log(h, AV_LOG_INFO, "%d usable playlists:\n", num_title_idx);
143  if (num_title_idx < 1) {
144  return AVERROR(EIO);
145  }
146 
147  /* if playlist was not given, select longest playlist */
148  if (bd->playlist < 0) {
149  uint64_t duration = 0;
150  int i;
151  for (i = 0; i < num_title_idx; i++) {
152  BLURAY_TITLE_INFO *info = bd_get_title_info(bd->bd, i, 0);
153 
154  av_log(h, AV_LOG_INFO, "playlist %05d.mpls (%d:%02d:%02d)\n",
155  info->playlist,
156  ((int)(info->duration / 90000) / 3600),
157  ((int)(info->duration / 90000) % 3600) / 60,
158  ((int)(info->duration / 90000) % 60));
159 
160  if (info->duration > duration) {
161  bd->playlist = info->playlist;
162  duration = info->duration;
163  }
164 
165  bd_free_title_info(info);
166  }
167  av_log(h, AV_LOG_INFO, "selected %05d.mpls\n", bd->playlist);
168  }
169 
170  /* select playlist */
171  if (bd_select_playlist(bd->bd, bd->playlist) <= 0) {
172  av_log(h, AV_LOG_ERROR, "bd_select_playlist(%05d.mpls) failed\n", bd->playlist);
173  return AVERROR(EIO);
174  }
175 
176  /* select angle */
177  if (bd->angle >= 0) {
178  bd_select_angle(bd->bd, bd->angle);
179  }
180 
181  /* select chapter */
182  if (bd->chapter > 1) {
183  bd_seek_chapter(bd->bd, bd->chapter - 1);
184  }
185 
186  return 0;
187 }
188 
189 static int bluray_read(URLContext *h, unsigned char *buf, int size)
190 {
191  BlurayContext *bd = h->priv_data;
192  int len;
193 
194  if (!bd || !bd->bd) {
195  return AVERROR(EFAULT);
196  }
197 
198  len = bd_read(bd->bd, buf, size);
199 
200  return len == 0 ? AVERROR_EOF : len;
201 }
202 
203 static int64_t bluray_seek(URLContext *h, int64_t pos, int whence)
204 {
205  BlurayContext *bd = h->priv_data;
206 
207  if (!bd || !bd->bd) {
208  return AVERROR(EFAULT);
209  }
210 
211  switch (whence) {
212  case SEEK_SET:
213  case SEEK_CUR:
214  case SEEK_END:
215  return bd_seek(bd->bd, pos);
216 
217  case AVSEEK_SIZE:
218  return bd_get_title_size(bd->bd);
219  }
220 
221  av_log(h, AV_LOG_ERROR, "Unsupported whence operation %d\n", whence);
222  return AVERROR(EINVAL);
223 }
224 
225 
227  .name = "bluray",
228  .url_close = bluray_close,
229  .url_open = bluray_open,
230  .url_read = bluray_read,
231  .url_seek = bluray_seek,
232  .priv_data_size = sizeof(BlurayContext),
233  .priv_data_class = &bluray_context_class,
234 };
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
opt.h
playlist
Definition: hls.c:102
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
int64_t
long long int64_t
Definition: coverity.c:34
AVOption
AVOption.
Definition: opt.h:429
AVSEEK_SIZE
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:468
BLURAY_PROTO_PREFIX
#define BLURAY_PROTO_PREFIX
Definition: bluray.c:29
ff_bluray_protocol
const URLProtocol ff_bluray_protocol
Definition: bluray.c:226
URLProtocol
Definition: url.h:51
bluray_close
static int bluray_close(URLContext *h)
Definition: bluray.c:103
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
bluray_seek
static int64_t bluray_seek(URLContext *h, int64_t pos, int whence)
Definition: bluray.c:203
duration
int64_t duration
Definition: movenc.c:65
info
MIPS optimizations info
Definition: mips.txt:2
bluray_context_class
static const AVClass bluray_context_class
Definition: bluray.c:52
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
bluray_open
static int bluray_open(URLContext *h, const char *path, int flags)
Definition: bluray.c:113
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
options
Definition: swscale.c:42
check_disc_info
static int check_disc_info(URLContext *h)
Definition: bluray.c:60
size
int size
Definition: twinvq_data.h:10344
URLProtocol::name
const char * name
Definition: url.h:52
BlurayContext::bd
BLURAY * bd
Definition: bluray.c:35
av_strstart
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:36
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
options
static const AVOption options[]
Definition: bluray.c:44
URLContext
Definition: url.h:35
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
OFFSET
#define OFFSET(x)
Definition: bluray.c:43
url.h
len
int len
Definition: vorbis_enc_data.h:426
BlurayContext
Definition: bluray.c:32
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
bluray_read
static int bluray_read(URLContext *h, unsigned char *buf, int size)
Definition: bluray.c:189
pos
unsigned int pos
Definition: spdifenc.c:414
BlurayContext::playlist
int playlist
Definition: bluray.c:37
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
MIN_PLAYLIST_LENGTH
#define MIN_PLAYLIST_LENGTH
Definition: bluray.c:30
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:356
BlurayContext::chapter
int chapter
Definition: bluray.c:39
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070
BlurayContext::angle
int angle
Definition: bluray.c:38
avstring.h