From patchwork Sun Jan 15 08:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Ionascu X-Patchwork-Id: 40004 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1d43:b0:b8:6755:f97e with SMTP id cs3csp229511pzb; Sun, 15 Jan 2023 00:50:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXuropx4k5xkoKi9HagAc5Z/Wsd43BtpixWXn2YkBFn8Z0PPOR7SzZgHUbzRx8oKQuh8e0/8 X-Received: by 2002:a17:906:3e58:b0:7c0:fa2c:fc9b with SMTP id t24-20020a1709063e5800b007c0fa2cfc9bmr7870796eji.55.1673772640886; Sun, 15 Jan 2023 00:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673772640; cv=none; d=google.com; s=arc-20160816; b=czyGuylM7fYrx/RTg9jnbM4tFC7jQhoaw+r5TPuBJYPZ2hXTZZ/6IkPW4LJOoDNPw2 EsriBBH43J9WV7cqXBWiFSzQE1w8OdtPK/4OAy/ZaNtDDdImXvaJyvgnYMW8fNpvGv43 a6SZLoNPK3GGUPbSud6sVS4kAK9SaxlxvuilzIYgDmDydCW6hDwc/kPjhWa1etCXL8oA nlh3h35CJQQr5rw9xBCjhu/+vkiFqhFUnCyluANwEvhkpQKbkoNcxcchD7hdVUdgEMo+ tiCJxrSp0O6xaohCRxsMN6uhZUcmnp99we0AMGjh65eKxbX2fE4uBeN1AziSdzScFawK Jt9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=1EIdROHZt44vN5lYUQTJRcOL+WPqThd+224cmQDN1ew=; b=YjJ0SGCssIyc8L2xWWwi58Ab1Wsf6aybdnkmaSScUcpN/NyVbyynjBMgYeHs9ANB3a tFA85HqV6z8sIt4nSxdHQoHzBZdwq1mlguNtlYXpWksU5n+wTlCzH0+tkqMPE7RPpHhf kqXLq95QmtGCScqIJ3x/1OrgR9PSJmdPpj8Mcnkh5Ox4YauM96SeItS+OdQcBB3r4cOw 7tZqSfLnWKYEelD6QtXkg9TOKtAlTjzuASQTqoEjDlg4y8EnlthtTAuRaF4WCDwJDbQt GHesSPIpRHz/EK0OM8wdC9sRZpC682y1zK6aEYWEIG0GAbfQsIse+DmUtKXPKD7nWT3p 84Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NiKi8JKO; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sa15-20020a1709076d0f00b0084c464789absi27966063ejc.781.2023.01.15.00.50.40; Sun, 15 Jan 2023 00:50:40 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NiKi8JKO; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF17068BBCB; Sun, 15 Jan 2023 10:50:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0803C68A2DE for ; Sun, 15 Jan 2023 10:50:31 +0200 (EET) Received: by mail-wm1-f42.google.com with SMTP id l41-20020a05600c1d2900b003daf986faaeso188106wms.3 for ; Sun, 15 Jan 2023 00:50:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1Xclp+ERMS5Znx0DbgogqidiVPP57br1jHuFXu94JwU=; b=NiKi8JKOYTStfBujkOweV62gX3yJ0J3X0d3pBamzaNrlVtYZQ0e06J/Jz0+oPCBeZ0 Ui9YIiJoM5kF/96CTq+8w/sHMK7vcCIB/OyObHlYHP8a2mpkqwJKLFlQ/CUOT+Wxt+44 NOmU61FE94GlTncbtq+1jKWgIP9Rrp5I237/Px3WehDg4HLt6rNEqcbHyOq7k0vJDUwk wDh4OBX785hyKzJNGPsH8N/sJjvhEiuWJvh+oglSteIxyiH9RoN+exeARgM8ZFpWt7Ft NIK5ZrmQmrBlkMKgOR94mVXDzfxr/UaJSUPFv5cXenWBjK4Yzuwov27xWipOtESyg0fH BADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1Xclp+ERMS5Znx0DbgogqidiVPP57br1jHuFXu94JwU=; b=tmJKxrcF1xESZLvwu/1Vi/1Q3zewGvZPEv4FEbnVJzhK6D+4dTBfmXQmv/fiYvcDyz UuXKpi5ahXS34mGDYVEG85Li4FInKNGOvoGZQ1I/lc52hHOgHb0XpALZjwzexklSBPF+ qsQeC2PqQSV1uG2HwS3b+z0h4cIFFzPAOa82iJGTIVdgqNa/l+F2192fOqA3K6Emanl+ kHAwIBJtAmwYwmd0E5WOS+OpV2XY2oD4f86ZKgSVUu2vC8X7UcdWTV9l3dvPxaj82E1e 5n2nB4VFHvyI/yp27gC0ZKrwhu2ymrLX2u6WUUo0ExHkZh7mX/G09mvD0bZoTf7oWa2G xqww== X-Gm-Message-State: AFqh2kr748AsGSOtPyf/eUeqQIvC9YXkuYqaqVZIhIQmyexq5eKDIrWz xj/TVYU08PYraRjKDCSTP4rAzlREi53b6Dcc X-Received: by 2002:a05:600c:4e0c:b0:3d9:eedd:e7f1 with SMTP id b12-20020a05600c4e0c00b003d9eedde7f1mr4751353wmq.12.1673772629727; Sun, 15 Jan 2023 00:50:29 -0800 (PST) Received: from localhost.localdomain (host109-147-184-255.range109-147.btcentralplus.com. [109.147.184.255]) by smtp.gmail.com with ESMTPSA id 2-20020a05600c020200b003d9ef8ad6b2sm21737429wmi.13.2023.01.15.00.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 00:50:29 -0800 (PST) From: Stanislav Ionascu To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Jan 2023 08:50:21 +0000 Message-Id: <20230115085021.10890-1-stanislav.ionascu@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4] avformat/dvd: new dvd:// protocol for reading dvd folder/images X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Stanislav Ionascu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ErHId+LNOluj dvd:// protocol uses libdvdread for opening folders and/or disc-images, it then either identifies the longest title-set, or uses the title-set parameter. After opening the dvd, libdvdread-protocol will read and output all VOBs, in the cell and pack sequence defined by the program-chain. The (split)-VOB content that is streamed from the folder/disc by libdvdread, is given to ffmpeg probed demuxer/decoder, which decodes and presents the frames. The chapter and language stream information is present in the side-files (BUP/IFO), which are parsed for identifying the correct main video-title-set, but not attached to the stream information. Signed-off-by: Stanislav Ionascu --- configure | 5 + libavformat/Makefile | 1 + libavformat/dvd.c | 327 ++++++++++++++++++++++++++++++++++++++++ libavformat/protocols.c | 1 + 4 files changed, 334 insertions(+) create mode 100644 libavformat/dvd.c diff --git a/configure b/configure index df69d39669..4dcd1f1484 100755 --- a/configure +++ b/configure @@ -230,6 +230,7 @@ External library support: --enable-libdavs2 enable AVS2 decoding via libdavs2 [no] --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 and libraw1394 [no] + --enable-libdvdread enable DVD reading using libdvdread [no] --enable-libfdk-aac enable AAC de/encoding via libfdk-aac [no] --enable-libflite enable flite (voice synthesis) support via libflite [no] --enable-libfontconfig enable libfontconfig, useful for drawtext filter [no] @@ -1814,6 +1815,7 @@ EXTERNAL_LIBRARY_LIST=" libdav1d libdc1394 libdrm + libdvdread libflite libfontconfig libfreetype @@ -3557,6 +3559,7 @@ xv_outdev_deps="xlib_xv xlib_x11 xlib_xext" # protocols async_protocol_deps="threads" bluray_protocol_deps="libbluray" +dvd_protocol_deps="libdvdread" ffrtmpcrypt_protocol_conflict="librtmp_protocol" ffrtmpcrypt_protocol_deps_any="gcrypt gmp openssl mbedtls" ffrtmpcrypt_protocol_select="tcp_protocol" @@ -6568,6 +6571,8 @@ enabled libdav1d && require_pkg_config libdav1d "dav1d >= 0.5.0" "dav1d enabled libdavs2 && require_pkg_config libdavs2 "davs2 >= 1.6.0" davs2.h davs2_decoder_open enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new enabled libdrm && require_pkg_config libdrm libdrm xf86drm.h drmGetVersion +enabled libdvdread && enable dvdread +enabled dvdread && require_pkg_config libdvdread dvdread "dvdread/dvd_reader.h" DVDOpen2 enabled libfdk_aac && { check_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen || { require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac && warn "using libfdk without pkg-config"; } } diff --git a/libavformat/Makefile b/libavformat/Makefile index fa71ec12f7..b58ea0f4ac 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -644,6 +644,7 @@ OBJS-$(CONFIG_CONCAT_PROTOCOL) += concat.o OBJS-$(CONFIG_CONCATF_PROTOCOL) += concat.o OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o OBJS-$(CONFIG_DATA_PROTOCOL) += data_uri.o +OBJS-$(CONFIG_DVD_PROTOCOL) += dvd.o OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpcrypt.o rtmpdigest.o rtmpdh.o OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL) += rtmphttp.o OBJS-$(CONFIG_FILE_PROTOCOL) += file.o diff --git a/libavformat/dvd.c b/libavformat/dvd.c new file mode 100644 index 0000000000..7a70189c69 --- /dev/null +++ b/libavformat/dvd.c @@ -0,0 +1,327 @@ +/* + * DVD (libdvdread) protocol + * Copyright (c) 2023 Stan Ionascu + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "libavformat/avformat.h" +#include "libavformat/url.h" +#include "libavutil/avstring.h" +#include "libavutil/opt.h" + +#define DVD_PROTO_PREFIX "dvd:" +#define DVD_SECTOR_SIZE 2048 + +typedef struct { + const AVClass *class; + + dvd_reader_t *dvd; + dvd_logger_cb dvd_logger; + + int title_nr; + int angle_nr; + dvd_file_t *dvd_title_file; + ifo_handle_t *vmg_ifo; + ifo_handle_t *vts_ifo; + pgc_t *current_pgc; + int current_cell; + + int start_sector; + int current_sector; + int end_sector; + +} DvdProtocolContext; + +static int bcd2int(int bcd) +{ + return (((bcd & 0xf0) >> 4) * 10 + (bcd & 0x0f)); +} + +static void dvd_logger_ff(void *opaque, dvd_logger_level_t dvd_level, const char *fmt, va_list args) +{ + int level = AV_LOG_TRACE; + if (dvd_level == DVD_LOGGER_LEVEL_ERROR) { + level = AV_LOG_ERROR; + } else if (dvd_level == DVD_LOGGER_LEVEL_WARN) { + level = AV_LOG_WARNING; + } else if (dvd_level == DVD_LOGGER_LEVEL_INFO) { + level = AV_LOG_INFO; + } else if (dvd_level == DVD_LOGGER_LEVEL_DEBUG) { + level = AV_LOG_DEBUG; + } + av_vlog(opaque, level, fmt, args); + /* add new line */ + av_log(opaque, level, "\n"); +} + +static int ff_dvd_get_title_set_length(ifo_handle_t *vts_ifo, tt_srpt_t *tt_srpt, int title_nr) +{ + /* reindex 1 => 0 */ + int vts_title_number = tt_srpt->title[title_nr].vts_ttn - 1; + int pgc_number = vts_ifo->vts_ptt_srpt->title[vts_title_number].ptt[0].pgcn; + dvd_time_t *playback_time = &vts_ifo->vts_pgcit->pgci_srp[pgc_number - 1].pgc->playback_time; + + return (bcd2int(playback_time->hour) * 3600 + + bcd2int(playback_time->minute) * 60 + + bcd2int(playback_time->second)) * 1000; +} + +static void ff_dvd_set_program_chain_info(DvdProtocolContext *ctx, int title_nr, int ptt_nr) +{ + /* reindex 1 => 0 */ + int vts_title_number = ctx->vmg_ifo->tt_srpt->title[title_nr].vts_ttn - 1; + ptt_info_t *ptt = &ctx->vts_ifo->vts_ptt_srpt->title[vts_title_number].ptt[ptt_nr]; + int pgc_id = ptt->pgcn; + int pgn = ptt->pgn; + + ctx->current_pgc = ctx->vts_ifo->vts_pgcit->pgci_srp[pgc_id - 1].pgc; + ctx->current_cell = ctx->current_pgc->program_map[pgn - 1] - 1; + + /* change angle */ + if(ctx->current_pgc->cell_playback[ctx->current_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) { + ctx->current_cell += ctx->angle_nr; + } + + ctx->current_sector = ctx->start_sector = ctx->current_pgc->cell_playback[ctx->current_cell].first_sector; + ctx->end_sector = ctx->current_pgc->cell_playback[ctx->current_cell].last_sector; +} + +static int ff_dvd_get_next_cell(DvdProtocolContext *ctx) +{ + int next_cell = ctx->current_cell; + + /* fast-forward until last-cell */ + if (ctx->current_pgc->cell_playback[next_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK) { + ctx->current_cell += ctx->angle_nr; + while (next_cell < ctx->current_pgc->nr_of_cells && + ctx->current_pgc->cell_playback[next_cell].block_type != BLOCK_MODE_LAST_CELL) { + next_cell++; + } + } + + /* take next cell */ + next_cell++; + if (next_cell >= ctx->current_pgc->nr_of_cells) { + return -1; + } + + return next_cell; +} + +static int dvd_url_close(URLContext *h) +{ + DvdProtocolContext *ctx = h->priv_data; + ifoClose(ctx->vts_ifo); + ifoClose(ctx->vmg_ifo); + DVDCloseFile(ctx->dvd_title_file); + DVDClose(ctx->dvd); + return 0; +} + +static int dvd_url_open(URLContext *h, const char *path, int flags) +{ + DvdProtocolContext *ctx = h->priv_data; + const char *dvd_path = path; + ifo_handle_t *vmg_ifo, *vts_ifo; + tt_srpt_t *tt_srpt; + int num_vts, num_titles; + int longest_title_nr; + int64_t longest_title_length_ms = 0; + int vts_nr; + int title_set_nr; + char disc_volume_id[32]; + + ctx->vmg_ifo = ctx->vts_ifo = NULL; + ctx->dvd_logger.pf_log = &dvd_logger_ff; + + /* strip protocol from path */ + av_strstart(path, DVD_PROTO_PREFIX, &dvd_path); + + /* open dvd folder or disc */ + if ((ctx->dvd = DVDOpen2(h, &ctx->dvd_logger, dvd_path)) == NULL) { + av_log(h, AV_LOG_ERROR, "DVDOpen(%s) failed\n", dvd_path); + return AVERROR(EIO); + } + + if (DVDUDFVolumeInfo(ctx->dvd, &disc_volume_id[0], 32, NULL, 0) == 0) { + av_log(h, AV_LOG_INFO, "opened disc-volume-id: %s\n", disc_volume_id); + } + + /* read toc */ + if ((vmg_ifo = ifoOpen(ctx->dvd, 0)) == NULL) { + av_log(h, AV_LOG_ERROR, "ifoOpen(0) failed\n"); + return AVERROR(EIO); + } + + /* read titles */ + num_vts = vmg_ifo->vts_atrt->nr_of_vtss; + num_titles = vmg_ifo->tt_srpt->nr_of_srpts; + av_log(h, AV_LOG_INFO, "there are %d usable titles\n", num_titles); + + /* get title-set info(s) */ + tt_srpt = vmg_ifo->tt_srpt; + if (ctx->title_nr >= num_titles) { + av_log(h, AV_LOG_ERROR, "invalid title id %d\n", ctx->title_nr); + return AVERROR(EINVAL); + } + + for (vts_nr = 1; vts_nr <= num_vts; vts_nr++) { + int title_nr; + for (title_nr = 0; title_nr < num_titles; title_nr++) { + int title_length_ms; + + if (tt_srpt->title[title_nr].title_set_nr != vts_nr) { + continue; + } + + /* describe the title(s) info */ + if ((vts_ifo = ifoOpen(ctx->dvd, vts_nr)) == NULL) { + av_log(h, AV_LOG_ERROR, "ifoOpen(%d) failed\n", title_nr); + return AVERROR(ENOMEM); + } + + /* skip if video title set or program chain info is missing */ + if (vts_ifo->vtsi_mat == NULL || vts_ifo->vts_pgcit == NULL) { + ifoClose(vts_ifo); + av_log(h, AV_LOG_TRACE, "skip title %d as no vts or pgc info is present\n", + title_nr); + continue; + } + + /* skip if vts_ttn is incorrect */ + if (tt_srpt->title[title_nr].vts_ttn < 1 || + tt_srpt->title[title_nr].vts_ttn > num_titles) { + ifoClose(vts_ifo); + av_log(h, AV_LOG_WARNING, "skip title %d as vts_ttn is out of bounds\n", + title_nr); + continue; + } + + title_length_ms = ff_dvd_get_title_set_length(vts_ifo, tt_srpt, title_nr); + av_log(h, AV_LOG_INFO, "title %03d : (%d:%02d:%02d) and %d chapter(s)\n", + title_nr, + (title_length_ms / 3600000), + (title_length_ms % 3600000) / 60000, + (title_length_ms % 60000) / 1000, + tt_srpt->title[title_nr].nr_of_ptts); + + if (longest_title_length_ms <= title_length_ms) { + longest_title_nr = title_nr; + longest_title_length_ms = title_length_ms; + } + + ifoClose(vts_ifo); + } + } + + if (ctx->title_nr < 0) { + ctx->title_nr = longest_title_nr; + } + + /* check if title selection is valid */ + if (tt_srpt->title[ctx->title_nr].vts_ttn < 1 || + tt_srpt->title[ctx->title_nr].vts_ttn > num_titles) { + av_log(h, AV_LOG_INFO, "selected title %d is not valid, vts_ttn is out of bounds\n", + ctx->title_nr); + ifoClose(vmg_ifo); + return AVERROR(EIO); + } + + av_log(h, AV_LOG_INFO, "selected title %d\n", ctx->title_nr); + + if (ctx->angle_nr > 0 && ctx->angle_nr >= tt_srpt->title[ctx->title_nr].nr_of_angles) { + av_log(h, AV_LOG_ERROR, "incorrect angle selected %d out of %d angle(s)\n", + ctx->angle_nr, + tt_srpt->title[ctx->title_nr].nr_of_angles); + } + + /* open request title_set info */ + title_set_nr = tt_srpt->title[ctx->title_nr].title_set_nr; + if ((vts_ifo = ifoOpen(ctx->dvd, title_set_nr)) == NULL) { + av_log(h, AV_LOG_INFO, "ifoOpen(%d) failed\n", title_set_nr); + return AVERROR(ENOMEM); + } + + /* open file */ + if ((ctx->dvd_title_file = DVDOpenFile(ctx->dvd, title_set_nr, DVD_READ_TITLE_VOBS)) == NULL) { + av_log(h, AV_LOG_ERROR, "DVDOpenFile(%d) failed\n", title_set_nr); + return AVERROR(EIO); + } + + ctx->vmg_ifo = vmg_ifo; + ctx->vts_ifo = vts_ifo; + + ff_dvd_set_program_chain_info(ctx, ctx->title_nr, 0); + + return 0; +} + +static int dvd_url_read(URLContext *h, unsigned char *buf, int size) +{ + DvdProtocolContext *ctx = h->priv_data; + ssize_t blocks_got; + int num_blocks = size / DVD_SECTOR_SIZE; + + if (ctx->current_sector >= ctx->end_sector) { + int next_cell = ff_dvd_get_next_cell(ctx); + if (next_cell < 0) { + return AVERROR_EOF; + } + + ctx->current_cell = next_cell; + ctx->start_sector = ctx->current_pgc->cell_playback[ctx->current_cell].first_sector; + ctx->end_sector = ctx->current_pgc->cell_playback[ctx->current_cell].last_sector; + ctx->current_sector = ctx->start_sector; + } + + /* read all sectors that fit into buf */ + blocks_got = DVDReadBlocks(ctx->dvd_title_file, ctx->current_sector, num_blocks, buf); + if (blocks_got <= 0) { + av_log(h, AV_LOG_ERROR, "failed to DVDReadBlocks() %d blocks at offset %d\n", + num_blocks, ctx->current_sector); + return AVERROR(EIO); + } + ctx->current_sector += blocks_got; + return blocks_got <= 0 ? AVERROR_EOF : blocks_got * DVD_SECTOR_SIZE; +} + +#define OFFSET(x) offsetof(DvdProtocolContext, x) +static const AVOption options[] = { + {"title", "", OFFSET(title_nr), AV_OPT_TYPE_INT, { .i64=-1 }, -1, 9999, AV_OPT_FLAG_DECODING_PARAM }, + {"angle", "", OFFSET(angle_nr), AV_OPT_TYPE_INT, { .i64=0 }, 0, 256, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; +static const AVClass dvd_context_class = { + .class_name = "dvd", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +const URLProtocol ff_dvd_protocol = { + .name = "dvd", + .url_close = dvd_url_close, + .url_open = dvd_url_open, + .url_read = dvd_url_read, + .priv_data_size = sizeof(DvdProtocolContext), + .priv_data_class = &dvd_context_class, +}; diff --git a/libavformat/protocols.c b/libavformat/protocols.c index 9491dc7d00..ab0c988caf 100644 --- a/libavformat/protocols.c +++ b/libavformat/protocols.c @@ -30,6 +30,7 @@ extern const URLProtocol ff_concatf_protocol; extern const URLProtocol ff_crypto_protocol; extern const URLProtocol ff_data_protocol; extern const URLProtocol ff_fd_protocol; +extern const URLProtocol ff_dvd_protocol; extern const URLProtocol ff_ffrtmpcrypt_protocol; extern const URLProtocol ff_ffrtmphttp_protocol; extern const URLProtocol ff_file_protocol;