1- From 5582bd1c8aa667f9dc0ca6c14ffb916e7a666c0e Mon Sep 17 00:00:00 2001
1+ From 4fd069b5ab73b35872f01657cb274db8afae5663 Mon Sep 17 00:00:00 2001
22From: qianlongxu <qianlongxu@gmail.com>
33Date: Tue, 12 May 2026 16:26:37 +0800
44Subject: [PATCH] custom bluray fs for network Blu-ray Disc and BDMV
55
66---
77 libavformat/Makefile | 2 +-
8- libavformat/bluray.c | 128 ++++ ++++-
8+ libavformat/bluray.c | 63 ++++-
99 libavformat/bluray_custom_fs.c | 459 +++++++++++++++++++++++++++++++++
1010 libavformat/bluray_custom_fs.h | 33 +++
11- 4 files changed, 610 insertions(+), 12 deletions(-)
11+ 4 files changed, 544 insertions(+), 13 deletions(-)
1212 create mode 100644 libavformat/bluray_custom_fs.c
1313 create mode 100644 libavformat/bluray_custom_fs.h
1414
@@ -26,10 +26,10 @@ index e299e72..1f32e4c 100644
2626 OBJS-$(CONFIG_CONCAT_PROTOCOL) += concat.o
2727 OBJS-$(CONFIG_CONCATF_PROTOCOL) += concat.o
2828diff --git a/libavformat/bluray.c b/libavformat/bluray.c
29- index 1845551..eb43340 100644
29+ index 1845551..f23bfa4 100644
3030--- a/libavformat/bluray.c
3131+++ b/libavformat/bluray.c
32- @@ -21,23 +21,27 @@
32+ @@ -21,19 +21,21 @@
3333 */
3434
3535 #include <libbluray/bluray.h>
@@ -40,7 +40,6 @@ index 1845551..eb43340 100644
4040 #include "libavutil/opt.h"
4141+ #include "bluray_custom_fs.h"
4242+ #include "libavutil/dict.h"
43- + #include "libavformat/avformat.h"
4443
4544- #define BLURAY_PROTO_PREFIX "bluray:"
4645+ #define BLURAY_PROTO_PREFIX "bluray://"
@@ -55,12 +54,7 @@ index 1845551..eb43340 100644
5554 int playlist;
5655 int angle;
5756 int chapter;
58- /*int region;*/
59- + int title_idx;
60- } BlurayContext;
61-
62- #define OFFSET(x) offsetof(BlurayContext, x)
63- @@ -106,23 +110,58 @@ static int bluray_close(URLContext *h)
57+ @@ -106,23 +108,57 @@ static int bluray_close(URLContext *h)
6458 if (bd->bd) {
6559 bd_close(bd->bd);
6660 }
@@ -75,16 +69,15 @@ index 1845551..eb43340 100644
7569+ #define BLURAY_DEBUG_MASK 0xFFFFF //(0xFFFFF & ~DBG_STREAM)
7670+
7771+ static void bluray_DebugHandler(const char *psz)
78- {
72+ + {
7973+ size_t len = strlen(psz);
8074+ if(len < 1) return;
8175+ av_log(NULL, AV_LOG_INFO, "[bluray] %s\n",psz);
8276+ }
8377+ #endif
8478+
85- +
8679+ static int bluray_open(URLContext *h, const char *path, int flags, AVDictionary **options)
87- + {
80+ {
8881+ #ifdef DEBUG_BLURAY
8982+ bd_set_debug_mask(BLURAY_DEBUG_MASK);
9083+ bd_set_debug_handler(bluray_DebugHandler);
@@ -123,7 +116,7 @@ index 1845551..eb43340 100644
123116
124117 /* check if disc can be played */
125118 if (check_disc_info(h) < 0) {
126- @@ -150,6 +189 ,9 @@ static int bluray_open(URLContext *h, const char *path, int flags)
119+ @@ -150,6 +186 ,9 @@ static int bluray_open(URLContext *h, const char *path, int flags)
127120 int i;
128121 for (i = 0; i < num_title_idx; i++) {
129122 BLURAY_TITLE_INFO *info = bd_get_title_info(bd->bd, i, 0);
@@ -133,13 +126,7 @@ index 1845551..eb43340 100644
133126
134127 av_log(h, AV_LOG_INFO, "playlist %05d.mpls (%d:%02d:%02d)\n",
135128 info->playlist,
136- @@ -159,17 +201,19 @@ static int bluray_open(URLContext *h, const char *path, int flags)
137-
138- if (info->duration > duration) {
139- bd->playlist = info->playlist;
140- + bd->title_idx = i;
141- duration = info->duration;
142- }
129+ @@ -164,12 +203,13 @@ static int bluray_open(URLContext *h, const char *path, int flags)
143130
144131 bd_free_title_info(info);
145132 }
@@ -156,83 +143,19 @@ index 1845551..eb43340 100644
156143 return AVERROR(EIO);
157144 }
158145
159- @@ -222,13 +266,75 @@ static int64_t bluray_seek(URLContext *h, int64_t pos, int whence)
146+ @@ -222,11 +262,10 @@ static int64_t bluray_seek(URLContext *h, int64_t pos, int whence)
160147 return AVERROR(EINVAL);
161148 }
162149
163- + static int bluray_parse_priv(AVFormatContext *ic, URLContext *h)
164- + {
165- + BlurayContext *bd = h->priv_data;
166- + BLURAY_TITLE_INFO *title_info = NULL;
167- + BLURAY_CLIP_INFO clip_info;
168- +
169- + int v_idx = 0;
170- + int a_idx = 0;
171- + int s_idx = 0;
172- + int ret = 0;
173- +
174- + if (!bd || !bd->bd) {
175- + return AVERROR(EFAULT);
176- + }
177- +
178- + title_info = bd_get_title_info(bd->bd, bd->title_idx, 0);
179- + if (!title_info) {
180- + return AVERROR(EFAULT);
181- + }
182- +
183- + if (title_info->clip_count <= 0) {
184- + ret = EFAULT;
185- + goto fail;
186- + }
187- + clip_info = title_info->clips[0];
188- +
189- + for (int i = 0; i < ic->nb_streams; i++) {
190- + if (ic->streams[i] && ic->streams[i]->codecpar) {
191- + switch (ic->streams[i]->codecpar->codec_type) {
192- + case AVMEDIA_TYPE_VIDEO:
193- + if (v_idx < clip_info.video_stream_count) {
194- + av_log(h, AV_LOG_INFO, "video stream %d lang = %s\n", v_idx, clip_info.video_streams[v_idx].lang);
195- + av_dict_set(&ic->streams[i]->metadata, "language", clip_info.video_streams[v_idx].lang, AV_DICT_DONT_OVERWRITE);
196- + v_idx++;
197- + }
198- + break;
199- + case AVMEDIA_TYPE_AUDIO:
200- + if (a_idx < clip_info.audio_stream_count) {
201- + av_log(h, AV_LOG_INFO, "audio stream %d lang = %s\n", a_idx, clip_info.audio_streams[a_idx].lang);
202- + av_dict_set(&ic->streams[i]->metadata, "language", clip_info.audio_streams[a_idx].lang, AV_DICT_DONT_OVERWRITE);
203- + a_idx++;
204- + }
205- + break;
206- + case AVMEDIA_TYPE_SUBTITLE:
207- + if (s_idx < clip_info.pg_stream_count) {
208- + av_log(h, AV_LOG_INFO, "subtitle stream %d lang = %s\n", s_idx, clip_info.pg_streams[s_idx].lang);
209- + av_dict_set(&ic->streams[i]->metadata, "language", clip_info.pg_streams[s_idx].lang, AV_DICT_DONT_OVERWRITE);
210- + s_idx++;
211- + }
212- + break;
213- + default:
214- + break;
215- + }
216- + }
217- + }
218- +
219- + fail:
220- + bd_free_title_info(title_info);
221- +
222- + return ret != 0 ? AVERROR(ret) : 0;
223- + }
224-
150+ -
225151 const URLProtocol ff_bluray_protocol = {
226152 .name = "bluray",
227153 .url_close = bluray_close,
228154- .url_open = bluray_open,
229155+ .url_open2 = bluray_open,
230156 .url_read = bluray_read,
231157 .url_seek = bluray_seek,
232- + .url_parse_priv = bluray_parse_priv,
233158 .priv_data_size = sizeof(BlurayContext),
234- .priv_data_class = &bluray_context_class,
235- };
236159diff --git a/libavformat/bluray_custom_fs.c b/libavformat/bluray_custom_fs.c
237160new file mode 100644
238161index 0000000..b82e0b2
0 commit comments