FFmpeg
dvdvideodec.c
Go to the documentation of this file.
1 /*
2  * DVD-Video demuxer, powered by libdvdnav and libdvdread
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  * See doc/demuxers.texi for a high-level overview.
23  *
24  * The tactical approach is as follows:
25  * 1) Open the volume with dvdread
26  * 2) Analyze the user-requested title and PGC coordinates in the IFO structures
27  * 3) Request playback at the coordinates and chosen angle with dvdnav
28  * 5) Begin the playback (reading and demuxing) of MPEG-PS blocks
29  * 6) End playback if navigation goes backwards, to a menu, or a different PGC or angle
30  * 7) Close the dvdnav VM, and free dvdread's IFO structures
31  */
32 
33 #include <inttypes.h>
34 
35 #include <dvdnav/dvdnav.h>
36 #include <dvdread/dvd_reader.h>
37 #include <dvdread/ifo_read.h>
38 #include <dvdread/ifo_types.h>
39 #include <dvdread/nav_read.h>
40 
41 #include "libavutil/avstring.h"
42 #include "libavutil/avutil.h"
43 #include "libavutil/intreadwrite.h"
44 #include "libavutil/mem.h"
45 #include "libavutil/opt.h"
46 #include "libavutil/samplefmt.h"
47 #include "libavutil/time.h"
48 #include "libavutil/timestamp.h"
49 
50 #include "avformat.h"
51 #include "avio_internal.h"
52 #include "avlanguage.h"
53 #include "demux.h"
54 #include "dvdclut.h"
55 #include "internal.h"
56 #include "url.h"
57 
58 #define DVDVIDEO_MAX_PS_SEARCH_BLOCKS 128
59 #define DVDVIDEO_BLOCK_SIZE 2048
60 #define DVDVIDEO_TIME_BASE_Q (AVRational) { 1, 90000 }
61 #define DVDVIDEO_PTS_WRAP_BITS 64 /* VOBUs use 32 (PES allows 33) */
62 #define DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE 1024
63 
64 #define PCI_START_BYTE 45 /* complement dvdread's DSI_START_BYTE */
65 static const uint8_t dvdvideo_nav_header[4] = { 0x00, 0x00, 0x01, 0xBF };
66 
72 };
73 static const char dvdvideo_subp_viewport_labels[4][13] = {
74  "Fullscreen", "Widescreen", "Letterbox", "Pan and Scan"
75 };
76 
78  int startcode;
80  int width;
81  int height;
84  int has_cc;
86 
88  int startcode;
92  int bit_depth;
96  const char *lang_iso;
98 
104  const char *lang_iso;
106 
107 typedef struct DVDVideoPlaybackState {
108  int celln; /* ID of the active cell */
109  int entry_pgn; /* ID of the PG we are starting in */
110  int in_pgc; /* if our navigator is in the PGC */
111  int in_ps; /* if our navigator is in the program stream */
112  int in_vts; /* if our navigator is in the VTS */
113  int64_t nav_pts; /* PTS according to IFO, not frame-accurate */
114  uint64_t pgc_duration_est; /* estimated duration as reported by IFO */
115  uint64_t pgc_elapsed; /* the elapsed time of the PGC, cell-relative */
116  int pgc_nb_pg_est; /* number of PGs as reported by IFOs */
117  int pgcn; /* ID of the PGC we are playing */
118  int pgn; /* ID of the PG we are in now */
119  int ptt; /* ID of the chapter we are in now */
120  int64_t ts_offset; /* PTS discontinuity offset (ex. VOB change) */
121  uint32_t vobu_duration; /* duration of the current VOBU */
122  uint32_t vobu_e_ptm; /* end PTM of the current VOBU */
123  int vtsn; /* ID of the active VTS (video title set) */
124  uint64_t *pgc_pg_times_est; /* PG start times as reported by IFO */
125  pgc_t *pgc; /* handle to the active PGC */
126  dvdnav_t *dvdnav; /* handle to the dvdnav VM */
127 
128  /* the following fields are only used for menu playback */
129  int celln_start; /* starting cell number */
130  int celln_end; /* ending cell number */
131  int sector_offset; /* current sector relative to the current VOB */
132  uint32_t sector_end; /* end sector relative to the current VOBU */
133  uint32_t vobu_next; /* the next VOBU pointer */
134  uint32_t vobu_remaining; /* remaining blocks for current VOBU */
135  dvd_file_t *vob_file; /* handle to the menu VOB (VMG or VTS) */
137 
138 typedef struct DVDVideoDemuxContext {
139  const AVClass *class;
140 
141  /* options */
142  int opt_angle; /* the user-provided angle number (1-indexed) */
143  int opt_chapter_end; /* the user-provided exit PTT (0 for last) */
144  int opt_chapter_start; /* the user-provided entry PTT (1-indexed) */
145  int opt_menu; /* demux menu domain instead of title domain */
146  int opt_menu_lu; /* the menu language unit (logical grouping) */
147  int opt_menu_vts; /* the menu VTS, or 0 for VMG (main menu) */
148  int opt_pg; /* the user-provided PG number (1-indexed) */
149  int opt_pgc; /* the user-provided PGC number (1-indexed) */
150  int opt_preindex; /* pre-indexing mode (2-pass read) */
151  int opt_region; /* the user-provided region digit */
152  int opt_title; /* the user-provided title number (1-indexed) */
153  int opt_trim; /* trim padding cells at beginning */
154 
155  /* subdemux */
156  AVFormatContext *mpeg_ctx; /* context for inner demuxer */
157  uint8_t *mpeg_buf; /* buffer for inner demuxer */
158  FFIOContext mpeg_pb; /* buffer context for inner demuxer */
159 
160  /* volume */
161  dvd_reader_t *dvdread; /* handle to libdvdread */
162  ifo_handle_t *vmg_ifo; /* handle to the VMG (VIDEO_TS.IFO) */
163  ifo_handle_t *vts_ifo; /* handle to the active VTS (VTS_nn_n.IFO) */
164 
165  /* playback control */
166  int64_t first_pts; /* the PTS of the first video keyframe */
167  int play_end; /* signal EOF to the parent demuxer */
168  DVDVideoPlaybackState play_state; /* the active playback state */
169  int play_started; /* signal that playback has started */
170  int segment_started; /* signal that subdemuxer is on a segment */
172 
173 static void dvdvideo_libdvdread_log(void *opaque, dvd_logger_level_t level,
174  const char *msg, va_list msg_va)
175 {
176  AVFormatContext *s = opaque;
177  char msg_buf[DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE];
178  int lavu_level = AV_LOG_DEBUG;
179 
180  vsnprintf(msg_buf, sizeof(msg_buf), msg, msg_va);
181 
182  if (level == DVD_LOGGER_LEVEL_ERROR)
183  lavu_level = AV_LOG_ERROR;
184  else if (level == DVD_LOGGER_LEVEL_WARN)
185  lavu_level = AV_LOG_WARNING;
186 
187  av_log(s, lavu_level, "libdvdread: %s\n", msg_buf);
188 }
189 
190 static void dvdvideo_libdvdnav_log(void *opaque, dvdnav_logger_level_t level,
191  const char *msg, va_list msg_va)
192 {
193  AVFormatContext *s = opaque;
194  char msg_buf[DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE];
195  int lavu_level = AV_LOG_DEBUG;
196 
197  vsnprintf(msg_buf, sizeof(msg_buf), msg, msg_va);
198 
199  if (level == DVDNAV_LOGGER_LEVEL_ERROR)
200  lavu_level = AV_LOG_ERROR;
201  /* some discs have invalid language codes set for menus, which throws noisy warnings */
202  else if (level == DVDNAV_LOGGER_LEVEL_WARN && !av_strstart(msg, "Language", NULL))
203  lavu_level = AV_LOG_WARNING;
204 
205  av_log(s, lavu_level, "libdvdnav: %s\n", msg_buf);
206 }
207 
209 {
210  DVDVideoDemuxContext *c = s->priv_data;
211 
212  if (c->vts_ifo)
213  ifoClose(c->vts_ifo);
214 
215  if (c->vmg_ifo)
216  ifoClose(c->vmg_ifo);
217 
218  if (c->dvdread)
219  DVDClose(c->dvdread);
220 }
221 
223 {
224  DVDVideoDemuxContext *c = s->priv_data;
225 
226  dvd_logger_cb dvdread_log_cb;
227  title_info_t title_info;
228 
229  dvdread_log_cb = (dvd_logger_cb) { .pf_log = dvdvideo_libdvdread_log };
230  c->dvdread = DVDOpen2(s, &dvdread_log_cb, s->url);
231 
232  if (!c->dvdread) {
233  av_log(s, AV_LOG_ERROR, "Unable to open the DVD-Video structure\n");
234 
235  return AVERROR_EXTERNAL;
236  }
237 
238  if (!(c->vmg_ifo = ifoOpen(c->dvdread, 0))) {
239  av_log(s, AV_LOG_ERROR, "Unable to open the VMG (VIDEO_TS.IFO)\n");
240 
241  return AVERROR_EXTERNAL;
242  }
243 
244  if (c->opt_menu) {
245  if (c->opt_menu_vts > 0 && !(c->vts_ifo = ifoOpen(c->dvdread, c->opt_menu_vts))) {
246  av_log(s, AV_LOG_ERROR, "Unable to open IFO structure for VTS %d\n", c->opt_menu_vts);
247 
248  return AVERROR_EXTERNAL;
249  }
250 
251  return 0;
252  }
253 
254  if (c->opt_title > c->vmg_ifo->tt_srpt->nr_of_srpts) {
255  av_log(s, AV_LOG_ERROR, "Title %d not found\n", c->opt_title);
256 
258  }
259 
260  title_info = c->vmg_ifo->tt_srpt->title[c->opt_title - 1];
261  if (c->opt_angle > title_info.nr_of_angles) {
262  av_log(s, AV_LOG_ERROR, "Angle %d not found\n", c->opt_angle);
263 
265  }
266 
267  if (title_info.nr_of_ptts < 1) {
268  av_log(s, AV_LOG_ERROR, "Title %d has invalid headers (no PTTs found)\n", c->opt_title);
269 
270  return AVERROR_INVALIDDATA;
271  }
272 
273  if (c->opt_chapter_start > title_info.nr_of_ptts ||
274  (c->opt_chapter_end > 0 && c->opt_chapter_end > title_info.nr_of_ptts)) {
275  av_log(s, AV_LOG_ERROR, "Chapter (PTT) range [%d, %d] is invalid\n",
276  c->opt_chapter_start, c->opt_chapter_end);
277 
278  return AVERROR_INVALIDDATA;
279  }
280 
281  if (!(c->vts_ifo = ifoOpen(c->dvdread, title_info.title_set_nr))) {
282  av_log(s, AV_LOG_ERROR, "Unable to process IFO structure for VTS %d\n",
283  title_info.title_set_nr);
284 
285  return AVERROR_EXTERNAL;
286  }
287 
288  if (title_info.vts_ttn < 1 ||
289  title_info.vts_ttn > 99 ||
290  title_info.vts_ttn > c->vts_ifo->vts_ptt_srpt->nr_of_srpts ||
291  c->vts_ifo->vtsi_mat->nr_of_vts_audio_streams > 8 ||
292  c->vts_ifo->vtsi_mat->nr_of_vts_subp_streams > 32) {
293 
294  av_log(s, AV_LOG_ERROR, "Title %d has invalid headers in VTS\n", c->opt_title);
295  return AVERROR_INVALIDDATA;
296  }
297 
298  return 0;
299 }
300 
301 static int dvdvideo_is_cell_promising(AVFormatContext *s, pgc_t *pgc, int celln)
302 {
303  dvd_time_t cell_duration = pgc->cell_playback[celln - 1].playback_time;
304 
305  return cell_duration.second >= 1 || cell_duration.minute >= 1 || cell_duration.hour >= 1;
306 }
307 
309 {
310  for (int i = 1; i <= pgc->nr_of_cells; i++)
311  if (dvdvideo_is_cell_promising(s, pgc, i))
312  return 1;
313 
314  return 0;
315 }
316 
318 {
319  if (state->vob_file)
320  DVDCloseFile(state->vob_file);
321 }
322 
324 {
325  DVDVideoDemuxContext *c = s->priv_data;
326  pgci_ut_t *pgci_ut;
327 
328  pgci_ut = c->opt_menu_vts ? c->vts_ifo->pgci_ut : c->vmg_ifo->pgci_ut;
329  if (!pgci_ut) {
330  av_log(s, AV_LOG_ERROR, "Invalid PGC table for menu [LU %d, PGC %d]\n",
331  c->opt_menu_lu, c->opt_pgc);
332 
333  return AVERROR_INVALIDDATA;
334  }
335 
336  if (c->opt_pgc < 1 ||
337  c->opt_menu_lu < 1 ||
338  c->opt_menu_lu > pgci_ut->nr_of_lus ||
339  c->opt_pgc > pgci_ut->lu[c->opt_menu_lu - 1].pgcit->nr_of_pgci_srp) {
340 
341  av_log(s, AV_LOG_ERROR, "Menu [LU %d, PGC %d] not found\n", c->opt_menu_lu, c->opt_pgc);
342 
343  return AVERROR(EINVAL);
344  }
345 
346  /* make sure the PGC is valid */
347  state->pgcn = c->opt_pgc - 1;
348  state->pgc = pgci_ut->lu[c->opt_menu_lu - 1].pgcit->pgci_srp[c->opt_pgc - 1].pgc;
349  if (!state->pgc || !state->pgc->program_map || !state->pgc->cell_playback) {
350  av_log(s, AV_LOG_ERROR, "Invalid PGC structure for menu [LU %d, PGC %d]\n",
351  c->opt_menu_lu, c->opt_pgc);
352 
353  return AVERROR_INVALIDDATA;
354  }
355 
356  /* make sure the PG is valid */
357  state->entry_pgn = c->opt_pg;
358  if (state->entry_pgn < 1 || state->entry_pgn > state->pgc->nr_of_programs) {
359  av_log(s, AV_LOG_ERROR, "Entry PG %d not found\n", state->entry_pgn);
360 
361  return AVERROR(EINVAL);
362  }
363 
364  /* make sure the program map isn't leading us to nowhere */
365  state->celln_start = state->pgc->program_map[state->entry_pgn - 1];
366  state->celln_end = state->pgc->nr_of_cells;
367  state->celln = state->celln_start;
368  if (state->celln_start > state->pgc->nr_of_cells) {
369  av_log(s, AV_LOG_ERROR, "Invalid PGC structure: program map points to unknown cell\n");
370 
371  return AVERROR_INVALIDDATA;
372  }
373 
374  state->sector_end = state->pgc->cell_playback[state->celln - 1].last_sector;
375  state->vobu_next = state->pgc->cell_playback[state->celln - 1].first_sector;
376  state->sector_offset = state->vobu_next;
377 
378  if (c->opt_menu_vts > 0)
379  state->in_vts = 1;
380 
381  if (!(state->vob_file = DVDOpenFile(c->dvdread, c->opt_menu_vts, DVD_READ_MENU_VOBS))) {
382  av_log(s, AV_LOG_ERROR, !c->opt_menu_vts ?
383  "Unable to open main menu VOB (VIDEO_TS.VOB)\n" :
384  "Unable to open menu VOBs for VTS %d\n", c->opt_menu_vts);
385 
386  return AVERROR_EXTERNAL;
387  }
388 
389  return 0;
390 }
391 
393  uint8_t *buf, int buf_size,
394  void (*flush_cb)(AVFormatContext *s))
395 {
396  int64_t blocks_read = 0;
397  uint8_t read_buf[DVDVIDEO_BLOCK_SIZE] = {0};
398  pci_t pci = (pci_t) {0};
399  dsi_t dsi = (dsi_t) {0};
400 
401  if (buf_size != DVDVIDEO_BLOCK_SIZE) {
402  av_log(s, AV_LOG_ERROR, "Invalid buffer size (expected=%d actual=%d)\n",
403  DVDVIDEO_BLOCK_SIZE, buf_size);
404 
405  return AVERROR(EINVAL);
406  }
407 
408  /* we were at the end of a vobu, so now go to the next one or EOF */
409  if (!state->vobu_remaining && state->in_pgc) {
410  if (state->vobu_next == SRI_END_OF_CELL) {
411  if (state->celln == state->celln_end && state->sector_offset > state->sector_end)
412  return AVERROR_EOF;
413 
414  state->celln++;
415  state->sector_offset = state->pgc->cell_playback[state->celln - 1].first_sector;
416  state->sector_end = state->pgc->cell_playback[state->celln - 1].last_sector;
417  } else {
418  state->sector_offset = state->vobu_next;
419  }
420  }
421 
422  /* continue reading the VOBU */
423  av_log(s, AV_LOG_TRACE, "reading block at offset %d\n", state->sector_offset);
424 
425  blocks_read = DVDReadBlocks(state->vob_file, state->sector_offset, 1, read_buf);
426  if (blocks_read != 1) {
427  av_log(s, AV_LOG_ERROR, "Unable to read VOB block: offset=%d blocks_read=%" PRId64 "\n",
428  state->sector_offset, blocks_read);
429 
430  return AVERROR_INVALIDDATA;
431  }
432 
433  /* we are at the start of a VOBU, so we are expecting a NAV packet */
434  if (!state->vobu_remaining) {
435  if (!memcmp(&read_buf[PCI_START_BYTE - 4], dvdvideo_nav_header, 4) ||
436  !memcmp(&read_buf[DSI_START_BYTE - 4], dvdvideo_nav_header, 4) ||
437  read_buf[PCI_START_BYTE - 1] != 0x00 ||
438  read_buf[DSI_START_BYTE - 1] != 0x01) {
439 
440  av_log(s, AV_LOG_ERROR, "Invalid NAV packet at offset %d: PCI or DSI header mismatch\n",
441  state->sector_offset);
442 
443  return AVERROR_INVALIDDATA;
444  }
445 
446  navRead_PCI(&pci, &read_buf[PCI_START_BYTE]);
447  navRead_DSI(&dsi, &read_buf[DSI_START_BYTE]);
448 
449  if (!pci.pci_gi.vobu_s_ptm ||
450  !pci.pci_gi.vobu_e_ptm ||
451  pci.pci_gi.vobu_s_ptm > pci.pci_gi.vobu_e_ptm) {
452 
453  av_log(s, AV_LOG_ERROR, "Invalid NAV packet at offset %d: PCI header is invalid\n",
454  state->sector_offset);
455 
456  return AVERROR_INVALIDDATA;
457  }
458 
459  state->vobu_remaining = dsi.dsi_gi.vobu_ea;
460  state->vobu_next = dsi.vobu_sri.next_vobu == SRI_END_OF_CELL ? SRI_END_OF_CELL :
461  dsi.dsi_gi.nv_pck_lbn + (dsi.vobu_sri.next_vobu & 0x7FFFFFFF);
462  state->sector_offset++;
463 
464  if (state->in_pgc) {
465  if (state->vobu_e_ptm != pci.pci_gi.vobu_s_ptm) {
466  if (flush_cb)
467  flush_cb(s);
468 
469  state->ts_offset += state->vobu_e_ptm - pci.pci_gi.vobu_s_ptm;
470  }
471  } else {
472  state->in_pgc = 1;
473  state->in_ps = 1;
474  }
475 
476  state->vobu_e_ptm = pci.pci_gi.vobu_e_ptm;
477 
478  av_log(s, AV_LOG_DEBUG, "NAV packet: sector=%d "
479  "vobu_s_ptm=%d vobu_e_ptm=%d ts_offset=%" PRId64 "\n",
480  dsi.dsi_gi.nv_pck_lbn,
481  pci.pci_gi.vobu_s_ptm, pci.pci_gi.vobu_e_ptm, state->ts_offset);
482 
483  return FFERROR_REDO;
484  }
485 
486  /* we are in the middle of a VOBU, so pass on the PS packet */
487  memcpy(buf, &read_buf, DVDVIDEO_BLOCK_SIZE);
488  state->sector_offset++;
489  state->vobu_remaining--;
490 
491  return DVDVIDEO_BLOCK_SIZE;
492 }
493 
495 {
496  if (!state->dvdnav)
497  return;
498 
499  /* not allocated by av_malloc() */
500  if (state->pgc_pg_times_est)
501  free(state->pgc_pg_times_est);
502 
503  if (dvdnav_close(state->dvdnav) != DVDNAV_STATUS_OK)
504  av_log(s, AV_LOG_ERROR, "Unable to close dvdnav successfully, dvdnav error: %s\n",
505  dvdnav_err_to_string(state->dvdnav));
506 }
507 
509 {
510  DVDVideoDemuxContext *c = s->priv_data;
511 
512  dvdnav_logger_cb dvdnav_log_cb;
513  dvdnav_status_t dvdnav_open_status;
514  int32_t disc_region_mask;
515  int32_t player_region_mask;
516  int cur_title, cur_pgcn, cur_pgn;
517  pgc_t *pgc;
518 
519  dvdnav_log_cb = (dvdnav_logger_cb) { .pf_log = dvdvideo_libdvdnav_log };
520  dvdnav_open_status = dvdnav_open2(&state->dvdnav, s, &dvdnav_log_cb, s->url);
521 
522  if (!state->dvdnav ||
523  dvdnav_open_status != DVDNAV_STATUS_OK ||
524  dvdnav_set_readahead_flag(state->dvdnav, 0) != DVDNAV_STATUS_OK ||
525  dvdnav_set_PGC_positioning_flag(state->dvdnav, 1) != DVDNAV_STATUS_OK ||
526  dvdnav_get_region_mask(state->dvdnav, &disc_region_mask) != DVDNAV_STATUS_OK) {
527 
528  av_log(s, AV_LOG_ERROR, "Unable to open the DVD for playback\n");
529  goto end_dvdnav_error;
530  }
531 
532  player_region_mask = c->opt_region > 0 ? (1 << (c->opt_region - 1)) : disc_region_mask;
533  if (dvdnav_set_region_mask(state->dvdnav, player_region_mask) != DVDNAV_STATUS_OK) {
534  av_log(s, AV_LOG_ERROR, "Unable to set the playback region code %d\n", c->opt_region);
535 
536  goto end_dvdnav_error;
537  }
538 
539  if (c->opt_pgc > 0 && c->opt_pg > 0) {
540  if (dvdnav_program_play(state->dvdnav, c->opt_title, c->opt_pgc, c->opt_pg) != DVDNAV_STATUS_OK) {
541  av_log(s, AV_LOG_ERROR, "Unable to start playback at title %d, PGC %d, PG %d\n",
542  c->opt_title, c->opt_pgc, c->opt_pg);
543 
544  goto end_dvdnav_error;
545  }
546 
547  state->pgcn = c->opt_pgc;
548  state->entry_pgn = c->opt_pg;
549  } else {
550  if (dvdnav_part_play(state->dvdnav, c->opt_title, c->opt_chapter_start) != DVDNAV_STATUS_OK ||
551  dvdnav_current_title_program(state->dvdnav, &cur_title, &cur_pgcn, &cur_pgn) != DVDNAV_STATUS_OK) {
552 
553  av_log(s, AV_LOG_ERROR, "Unable to start playback at title %d, chapter (PTT) %d\n",
554  c->opt_title, c->opt_chapter_start);
555  goto end_dvdnav_error;
556  }
557 
558  state->pgcn = cur_pgcn;
559  state->entry_pgn = cur_pgn;
560  }
561 
562  pgc = c->vts_ifo->vts_pgcit->pgci_srp[state->pgcn - 1].pgc;
563 
564  if (pgc->pg_playback_mode != 0) {
565  av_log(s, AV_LOG_ERROR, "Non-sequential PGCs, such as shuffles, are not supported\n");
566 
567  return AVERROR_PATCHWELCOME;
568  }
569 
570  if (c->opt_trim && !dvdvideo_is_pgc_promising(s, pgc)) {
571  av_log(s, AV_LOG_ERROR, "Title %d, PGC %d looks empty (may consist of padding cells), "
572  "if you want to try anyway, disable the -trim option\n",
573  c->opt_title, state->pgcn);
574 
575  return AVERROR_INVALIDDATA;
576  }
577 
578  if (dvdnav_angle_change(state->dvdnav, c->opt_angle) != DVDNAV_STATUS_OK) {
579  av_log(s, AV_LOG_ERROR, "Unable to start playback at angle %d\n", c->opt_angle);
580 
581  goto end_dvdnav_error;
582  }
583 
584  /* dvdnav_describe_title_chapters() performs several validations on the title structure */
585  /* take advantage of this side effect to increase chances of a safe navigation path */
586  state->pgc_nb_pg_est = dvdnav_describe_title_chapters(state->dvdnav, c->opt_title,
587  &state->pgc_pg_times_est,
588  &state->pgc_duration_est);
589 
590  /* dvdnav returning 0 PGs is documented as an error condition */
591  if (!state->pgc_nb_pg_est) {
592  av_log(s, AV_LOG_ERROR, "Unable to read chapter information for title %d\n", c->opt_title);
593 
594  goto end_dvdnav_error;
595  }
596 
597  state->nav_pts = dvdnav_get_current_time(state->dvdnav);
598  state->vtsn = c->vmg_ifo->tt_srpt->title[c->opt_title - 1].title_set_nr;
599  state->pgc = pgc;
600 
601  return 0;
602 
603 end_dvdnav_error:
604  if (state->dvdnav)
605  av_log(s, AV_LOG_ERROR, "dvdnav error: %s\n", dvdnav_err_to_string(state->dvdnav));
606  else
607  av_log(s, AV_LOG_ERROR, "dvdnav could not be initialized\n");
608 
609  return AVERROR_EXTERNAL;
610 }
611 
613  uint8_t *buf, int buf_size,
614  int *p_nav_event,
615  void (*flush_cb)(AVFormatContext *s))
616 {
617  DVDVideoDemuxContext *c = s->priv_data;
618 
619  uint8_t nav_buf[DVDVIDEO_BLOCK_SIZE] = {0};
620  int nav_event;
621  int nav_len;
622 
623  dvdnav_vts_change_event_t *e_vts;
624  dvdnav_cell_change_event_t *e_cell;
625  int cur_title, cur_pgcn, cur_pgn, cur_angle, cur_title_unused, cur_ptt, cur_nb_angles;
626  pci_t *e_pci;
627  dsi_t *e_dsi;
628 
629  if (buf_size != DVDVIDEO_BLOCK_SIZE) {
630  av_log(s, AV_LOG_ERROR, "Invalid buffer size (expected=%d actual=%d)\n",
631  DVDVIDEO_BLOCK_SIZE, buf_size);
632 
633  return AVERROR(EINVAL);
634  }
635 
636  for (int i = 0; i < DVDVIDEO_MAX_PS_SEARCH_BLOCKS; i++) {
637  if (ff_check_interrupt(&s->interrupt_callback))
638  return AVERROR_EXIT;
639 
640  if (dvdnav_get_next_block(state->dvdnav, nav_buf, &nav_event, &nav_len) != DVDNAV_STATUS_OK) {
641  av_log(s, AV_LOG_ERROR, "Unable to read next block of PGC\n");
642 
643  goto end_dvdnav_error;
644  }
645 
646  /* STOP event can come at any time and should be honored */
647  if (nav_event == DVDNAV_STOP)
648  return AVERROR_EOF;
649 
650  if (nav_len > DVDVIDEO_BLOCK_SIZE) {
651  av_log(s, AV_LOG_ERROR, "Invalid block size (expected<=%d actual=%d)\n",
652  DVDVIDEO_BLOCK_SIZE, nav_len);
653 
654  return AVERROR_INVALIDDATA;
655  }
656 
657  if (dvdnav_current_title_info(state->dvdnav, &cur_title, &cur_ptt) != DVDNAV_STATUS_OK) {
658  av_log(s, AV_LOG_ERROR, "Unable to determine current title coordinates\n");
659 
660  goto end_dvdnav_error;
661  }
662 
663  /* we somehow navigated to a menu */
664  if (cur_title == 0 || !dvdnav_is_domain_vts(state->dvdnav))
665  return AVERROR_EOF;
666 
667  if (dvdnav_current_title_program(state->dvdnav, &cur_title_unused, &cur_pgcn, &cur_pgn) != DVDNAV_STATUS_OK) {
668  av_log(s, AV_LOG_ERROR, "Unable to determine current PGC coordinates\n");
669 
670  goto end_dvdnav_error;
671  }
672 
673  /* we somehow left the PGC */
674  if (state->in_pgc && cur_pgcn != state->pgcn)
675  return AVERROR_EOF;
676 
677  if (dvdnav_get_angle_info(state->dvdnav, &cur_angle, &cur_nb_angles) != DVDNAV_STATUS_OK) {
678  av_log(s, AV_LOG_ERROR, "Unable to determine current video angle\n");
679 
680  goto end_dvdnav_error;
681  }
682 
683  av_log(s, nav_event == DVDNAV_BLOCK_OK ? AV_LOG_TRACE : AV_LOG_DEBUG,
684  "new block: i=%d nav_event=%d nav_len=%d cur_title=%d "
685  "cur_ptt=%d cur_angle=%d cur_celln=%d cur_pgcn=%d cur_pgn=%d "
686  "play_in_vts=%d play_in_pgc=%d play_in_ps=%d\n",
687  i, nav_event, nav_len, cur_title,
688  cur_ptt, cur_angle, state->celln, cur_pgcn, cur_pgn,
689  state->in_vts, state->in_pgc, state->in_ps);
690 
691  switch (nav_event) {
692  case DVDNAV_VTS_CHANGE:
693  if (state->in_vts)
694  return AVERROR_EOF;
695 
696  e_vts = (dvdnav_vts_change_event_t *) nav_buf;
697 
698  if (e_vts->new_vtsN == state->vtsn && e_vts->new_domain == DVD_DOMAIN_VTSTitle)
699  state->in_vts = 1;
700 
701  continue;
702  case DVDNAV_CELL_CHANGE:
703  if (!state->in_vts)
704  continue;
705 
706  e_cell = (dvdnav_cell_change_event_t *) nav_buf;
707 
708  av_log(s, AV_LOG_DEBUG, "new cell: prev=%d new=%d\n", state->celln, e_cell->cellN);
709 
710  if (!state->in_ps && !state->in_pgc) {
711  if (cur_title == c->opt_title &&
712  (c->opt_pgc || cur_ptt == c->opt_chapter_start) &&
713  cur_pgcn == state->pgcn &&
714  cur_pgn == state->entry_pgn) {
715 
716  state->in_pgc = 1;
717  }
718  } else if (state->celln >= e_cell->cellN || state->pgn > cur_pgn) {
719  return AVERROR_EOF;
720  }
721 
722  state->celln = e_cell->cellN;
723  state->ptt = cur_ptt;
724  state->pgn = cur_pgn;
725 
726  continue;
727  case DVDNAV_NAV_PACKET:
728  if (!state->in_pgc)
729  continue;
730 
731  if ((state->ptt > 0 && state->ptt > cur_ptt) ||
732  (c->opt_chapter_end > 0 && cur_ptt > c->opt_chapter_end)) {
733  return AVERROR_EOF;
734  }
735 
736  e_pci = dvdnav_get_current_nav_pci(state->dvdnav);
737  e_dsi = dvdnav_get_current_nav_dsi(state->dvdnav);
738 
739  if (e_pci == NULL || e_dsi == NULL ||
740  e_pci->pci_gi.vobu_s_ptm > e_pci->pci_gi.vobu_e_ptm) {
741 
742  av_log(s, AV_LOG_ERROR, "Invalid NAV packet\n");
743  return AVERROR_INVALIDDATA;
744  }
745 
746  state->vobu_duration = e_pci->pci_gi.vobu_e_ptm - e_pci->pci_gi.vobu_s_ptm;
747  state->pgc_elapsed += state->vobu_duration;
748  state->nav_pts = dvdnav_get_current_time(state->dvdnav);
749  state->ptt = cur_ptt;
750  state->pgn = cur_pgn;
751 
753  "NAV packet: s_ptm=%d e_ptm=%d "
754  "scr=%d lbn=%d vobu_duration=%d nav_pts=%" PRId64 "\n",
755  e_pci->pci_gi.vobu_s_ptm, e_pci->pci_gi.vobu_e_ptm,
756  e_dsi->dsi_gi.nv_pck_scr,
757  e_pci->pci_gi.nv_pck_lbn, state->vobu_duration, state->nav_pts);
758 
759  if (!state->in_ps) {
760  if (c->opt_trim && !dvdvideo_is_cell_promising(s, state->pgc, state->celln)) {
761  av_log(s, AV_LOG_INFO, "Skipping padding cell #%d\n", state->celln);
762 
763  i = 0;
764  continue;
765  }
766 
767  av_log(s, AV_LOG_DEBUG, "navigation: locked to program stream\n");
768 
769  state->in_ps = 1;
770  } else {
771  if (state->vobu_e_ptm != e_pci->pci_gi.vobu_s_ptm) {
772  if (flush_cb)
773  flush_cb(s);
774 
775  state->ts_offset += state->vobu_e_ptm - e_pci->pci_gi.vobu_s_ptm;
776  }
777  }
778 
779  state->vobu_e_ptm = e_pci->pci_gi.vobu_e_ptm;
780 
781  (*p_nav_event) = nav_event;
782 
783  return nav_len;
784  case DVDNAV_BLOCK_OK:
785  if (!state->in_ps) {
786  if (state->in_pgc)
787  i = 0; /* necessary in case we are skipping junk cells at the beginning */
788  continue;
789  }
790 
791  if (nav_len != DVDVIDEO_BLOCK_SIZE) {
792  av_log(s, AV_LOG_ERROR, "Invalid MPEG block size (expected=%d actual=%d)\n",
793  DVDVIDEO_BLOCK_SIZE, nav_len);
794 
795  return AVERROR_INVALIDDATA;
796  }
797 
798  if (cur_angle != c->opt_angle) {
799  av_log(s, AV_LOG_ERROR, "Unexpected angle change (expected=%d new=%d)\n",
800  c->opt_angle, cur_angle);
801 
802  return AVERROR_INPUT_CHANGED;
803  }
804 
805  memcpy(buf, &nav_buf, nav_len);
806 
807  if (state->pgn != cur_pgn)
808  av_log(s, AV_LOG_WARNING, "Unexpected PG change (expected=%d actual=%d); "
809  "this could be due to a missed NAV packet\n",
810  state->pgn, cur_pgn);
811 
812  (*p_nav_event) = nav_event;
813 
814  return nav_len;
815  case DVDNAV_WAIT:
816  if (dvdnav_wait_skip(state->dvdnav) != DVDNAV_STATUS_OK) {
817  av_log(s, AV_LOG_ERROR, "Unable to skip WAIT event\n");
818 
819  goto end_dvdnav_error;
820  }
821 
822  continue;
823  case DVDNAV_STILL_FRAME:
824  case DVDNAV_HOP_CHANNEL:
825  case DVDNAV_HIGHLIGHT:
826  if (state->in_ps)
827  return AVERROR_EOF;
828 
829  if (nav_event == DVDNAV_STILL_FRAME) {
830  if (dvdnav_still_skip(state->dvdnav) != DVDNAV_STATUS_OK) {
831  av_log(s, AV_LOG_ERROR, "Unable to skip still image\n");
832 
833  goto end_dvdnav_error;
834  }
835  }
836 
837  continue;
838  default:
839  continue;
840  }
841  }
842 
843  av_log(s, AV_LOG_ERROR, "Unable to find next program stream block\n");
844 
845  return AVERROR_INVALIDDATA;
846 
847 end_dvdnav_error:
848  av_log(s, AV_LOG_ERROR, "dvdnav error (title=%d pgc=%d pg=%d cell=%d): %s\n",
849  cur_title, cur_pgcn, cur_pgn, state->celln,
850  dvdnav_err_to_string(state->dvdnav));
851 
852  return AVERROR_EXTERNAL;
853 }
854 
856 {
857  DVDVideoDemuxContext *c = s->priv_data;
858 
859  uint64_t time_prev = 0;
860  int64_t total_duration = 0;
861 
862  int chapter_start = c->opt_chapter_start;
863  int chapter_end = c->opt_chapter_end > 0 ? c->opt_chapter_end : c->play_state.pgc_nb_pg_est - 1;
864 
865  /* dvdnav_describe_title_chapters() describes PGs rather than PTTs, so validate our range */
866  if (c->play_state.pgc_nb_pg_est == 1 ||
867  chapter_start > c->play_state.pgc_nb_pg_est ||
868  chapter_end > c->play_state.pgc_nb_pg_est) {
869 
870  s->duration = av_rescale_q(c->play_state.pgc_duration_est,
872  return 0;
873  }
874 
875  for (int i = chapter_start - 1; i < chapter_end; i++) {
876  uint64_t time_effective = c->play_state.pgc_pg_times_est[i] - c->play_state.nav_pts;
877 
878  if (time_effective - time_prev == 0)
879  continue;
880 
881  if (chapter_start != chapter_end &&
882  !avpriv_new_chapter(s, i, DVDVIDEO_TIME_BASE_Q, time_prev, time_effective, NULL)) {
883 
884  return AVERROR(ENOMEM);
885  }
886 
887  time_prev = time_effective;
888  total_duration = time_effective;
889  }
890 
891  if (c->opt_chapter_start == 1 && c->opt_chapter_end == 0)
892  s->duration = av_rescale_q(c->play_state.pgc_duration_est,
894  else
895  s->duration = av_rescale_q(total_duration,
897 
898  return 0;
899 }
900 
902 {
903  DVDVideoDemuxContext *c = s->priv_data;
904 
905  int ret = 0, interrupt = 0;
906  int nb_chapters = 0, last_ptt = c->opt_chapter_start;
907  uint64_t cur_chapter_offset = 0, cur_chapter_duration = 0;
909 
910  uint8_t nav_buf[DVDVIDEO_BLOCK_SIZE];
911  int nav_event;
912 
913  if (c->opt_chapter_start == c->opt_chapter_end)
914  return ret;
915 
916  if ((ret = dvdvideo_play_open(s, &state)) < 0)
917  return ret;
918 
919  if (state.pgc->nr_of_programs == 1)
920  goto end_close;
921 
923  "Indexing chapter markers, this will take a long time. Please wait...\n");
924 
925  while (!(interrupt = ff_check_interrupt(&s->interrupt_callback))) {
927  &nav_event, NULL);
928  if (ret < 0 && ret != AVERROR_EOF)
929  goto end_close;
930 
931  if (nav_event != DVDNAV_NAV_PACKET && ret != AVERROR_EOF)
932  continue;
933 
934  if (state.ptt == last_ptt) {
935  cur_chapter_duration += state.vobu_duration;
936  /* ensure we add the last chapter */
937  if (ret != AVERROR_EOF)
938  continue;
939  }
940 
941  if (cur_chapter_duration > 0) {
942  if (!avpriv_new_chapter(s, nb_chapters, DVDVIDEO_TIME_BASE_Q, cur_chapter_offset,
943  cur_chapter_offset + cur_chapter_duration, NULL)) {
944  ret = AVERROR(ENOMEM);
945  goto end_close;
946  }
947 
948  nb_chapters++;
949  }
950 
951  cur_chapter_offset += cur_chapter_duration;
952  cur_chapter_duration = state.vobu_duration;
953  last_ptt = state.ptt;
954 
955  if (ret == AVERROR_EOF)
956  break;
957  }
958 
959  if (interrupt) {
960  ret = AVERROR_EXIT;
961  goto end_close;
962  }
963 
964  if (ret < 0 && ret != AVERROR_EOF)
965  goto end_close;
966 
967  s->duration = av_rescale_q(state.pgc_elapsed, DVDVIDEO_TIME_BASE_Q, AV_TIME_BASE_Q);
968 
969  av_log(s, AV_LOG_INFO, "Chapter marker indexing complete\n");
970  ret = 0;
971 
972 end_close:
974 
975  return ret;
976 }
977 
978 static int dvdvideo_video_stream_analyze(AVFormatContext *s, video_attr_t video_attr,
980 {
982  int height = 0;
983  int width = 0;
984  int is_pal = video_attr.video_format == 1;
985 
986  framerate = is_pal ? (AVRational) { 25, 1 } : (AVRational) { 30000, 1001 };
987  height = is_pal ? 576 : 480;
988 
989  if (height > 0) {
990  switch (video_attr.picture_size) {
991  case 0: /* D1 */
992  width = 720;
993  break;
994  case 1: /* 4CIF */
995  width = 704;
996  break;
997  case 2: /* Half D1 */
998  width = 352;
999  break;
1000  case 3: /* CIF */
1001  width = 352;
1002  height /= 2;
1003  break;
1004  }
1005  }
1006 
1007  if (!width || !height) {
1008  av_log(s, AV_LOG_ERROR, "Invalid video stream parameters in the IFO headers, "
1009  "this could be an authoring error or empty title "
1010  "(video_format=%d picture_size=%d)\n",
1011  video_attr.video_format, video_attr.picture_size);
1012 
1013  return AVERROR_INVALIDDATA;
1014  }
1015 
1016  entry->startcode = 0x1E0;
1017  entry->codec_id = !video_attr.mpeg_version ? AV_CODEC_ID_MPEG1VIDEO : AV_CODEC_ID_MPEG2VIDEO;
1018  entry->width = width;
1019  entry->height = height;
1020  entry->dar = video_attr.display_aspect_ratio ? (AVRational) { 16, 9 } : (AVRational) { 4, 3 };
1021  entry->framerate = framerate;
1022  entry->has_cc = !is_pal && (video_attr.line21_cc_1 || video_attr.line21_cc_2);
1023 
1024  return 0;
1025 }
1026 
1029  enum AVStreamParseType need_parsing)
1030 {
1031  AVStream *st;
1032  FFStream *sti;
1033 
1034  st = avformat_new_stream(s, NULL);
1035  if (!st)
1036  return AVERROR(ENOMEM);
1037 
1038  st->id = entry->startcode;
1040  st->codecpar->codec_id = entry->codec_id;
1041  st->codecpar->width = entry->width;
1042  st->codecpar->height = entry->height;
1045 
1046 #if FF_API_R_FRAME_RATE
1047  st->r_frame_rate = entry->framerate;
1048 #endif
1049  st->avg_frame_rate = entry->framerate;
1050 
1051  sti = ffstream(st);
1052  sti->request_probe = 0;
1053  sti->need_parsing = need_parsing;
1054  sti->display_aspect_ratio = entry->dar;
1055 
1058 
1059  return 0;
1060 }
1061 
1063 {
1064  DVDVideoDemuxContext *c = s->priv_data;
1065 
1066  int ret;
1068  video_attr_t video_attr;
1069 
1070  if (c->opt_menu)
1071  video_attr = !c->opt_menu_vts ? c->vmg_ifo->vmgi_mat->vmgm_video_attr :
1072  c->vts_ifo->vtsi_mat->vtsm_video_attr;
1073  else
1074  video_attr = c->vts_ifo->vtsi_mat->vts_video_attr;
1075 
1076  if ((ret = dvdvideo_video_stream_analyze(s, video_attr, &entry)) < 0 ||
1078 
1079  av_log(s, AV_LOG_ERROR, "Unable to add video stream\n");
1080  return ret;
1081  }
1082 
1083  return 0;
1084 }
1085 
1086 static int dvdvideo_audio_stream_analyze(AVFormatContext *s, audio_attr_t audio_attr,
1087  uint16_t audio_control, DVDVideoPGCAudioStreamEntry *entry)
1088 {
1089  int startcode = 0;
1091  int sample_fmt = AV_SAMPLE_FMT_NONE;
1092  int sample_rate = 0;
1093  int bit_depth = 0;
1094  int nb_channels = 0;
1095  AVChannelLayout ch_layout = (AVChannelLayout) {0};
1096  char lang_dvd[3] = {0};
1097 
1098  int position = (audio_control & 0x7F00) >> 8;
1099 
1100  /* XXX(PATCHWELCOME): SDDS is not supported due to lack of sample material */
1101  switch (audio_attr.audio_format) {
1102  case 0: /* AC3 */
1104  sample_fmt = AV_SAMPLE_FMT_FLTP;
1105  sample_rate = 48000;
1106  startcode = 0x80 + position;
1107  break;
1108  case 2: /* MP1 */
1110  sample_fmt = audio_attr.quantization ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
1111  sample_rate = 48000;
1112  bit_depth = audio_attr.quantization ? 20 : 16;
1113  startcode = 0x1C0 + position;
1114  break;
1115  case 3: /* MP2 */
1117  sample_fmt = audio_attr.quantization ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
1118  sample_rate = 48000;
1119  bit_depth = audio_attr.quantization ? 20 : 16;
1120  startcode = 0x1C0 + position;
1121  break;
1122  case 4: /* DVD PCM */
1124  sample_fmt = audio_attr.quantization ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
1125  sample_rate = audio_attr.sample_frequency ? 96000 : 48000;
1126  bit_depth = audio_attr.quantization == 2 ? 24 : (audio_attr.quantization ? 20 : 16);
1127  startcode = 0xA0 + position;
1128  break;
1129  case 6: /* DCA */
1131  sample_fmt = AV_SAMPLE_FMT_FLTP;
1132  sample_rate = 48000;
1133  bit_depth = audio_attr.quantization == 2 ? 24 : (audio_attr.quantization ? 20 : 16);
1134  startcode = 0x88 + position;
1135  break;
1136  }
1137 
1138  nb_channels = audio_attr.channels + 1;
1139 
1140  if (codec_id == AV_CODEC_ID_NONE ||
1141  startcode == 0 ||
1142  sample_fmt == AV_SAMPLE_FMT_NONE ||
1143  sample_rate == 0 ||
1144  nb_channels == 0) {
1145 
1146  av_log(s, AV_LOG_ERROR, "Invalid audio stream parameters in the IFO headers, "
1147  "this could be an authoring error or dummy title "
1148  "(stream position %d in IFO)\n", position);
1149  return AVERROR_INVALIDDATA;
1150  }
1151 
1152  if (nb_channels == 1)
1154  else if (nb_channels == 2)
1156  else if (nb_channels == 6)
1158  else if (nb_channels == 7)
1160  else if (nb_channels == 8)
1162 
1163  /* XXX(PATCHWELCOME): IFO structures have metadata on karaoke tracks for additional features */
1164  if (audio_attr.application_mode == 1) {
1165  entry->disposition |= AV_DISPOSITION_KARAOKE;
1166 
1167  av_log(s, AV_LOG_WARNING, "Extended karaoke metadata is not supported at this time "
1168  "(stream id=%d)\n", startcode);
1169  }
1170 
1171  if (audio_attr.code_extension == 2)
1172  entry->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
1173  if (audio_attr.code_extension == 3 || audio_attr.code_extension == 4)
1174  entry->disposition |= AV_DISPOSITION_COMMENT;
1175 
1176  AV_WB16(lang_dvd, audio_attr.lang_code);
1177 
1178  entry->startcode = startcode;
1179  entry->codec_id = codec_id;
1180  entry->sample_rate = sample_rate;
1181  entry->bit_depth = bit_depth;
1182  entry->nb_channels = nb_channels;
1183  entry->ch_layout = ch_layout;
1184  entry->lang_iso = ff_convert_lang_to(lang_dvd, AV_LANG_ISO639_2_BIBL);
1185 
1186  return 0;
1187 }
1188 
1190  enum AVStreamParseType need_parsing)
1191 {
1192  AVStream *st;
1193  FFStream *sti;
1194 
1195  st = avformat_new_stream(s, NULL);
1196  if (!st)
1197  return AVERROR(ENOMEM);
1198 
1199  st->id = entry->startcode;
1201  st->codecpar->codec_id = entry->codec_id;
1202  st->codecpar->format = entry->sample_fmt;
1203  st->codecpar->sample_rate = entry->sample_rate;
1204  st->codecpar->bits_per_coded_sample = entry->bit_depth;
1205  st->codecpar->bits_per_raw_sample = entry->bit_depth;
1206  st->codecpar->ch_layout = entry->ch_layout;
1207  st->codecpar->ch_layout.nb_channels = entry->nb_channels;
1208  st->disposition = entry->disposition;
1209 
1210  if (entry->lang_iso)
1211  av_dict_set(&st->metadata, "language", entry->lang_iso, 0);
1212 
1213  sti = ffstream(st);
1214  sti->request_probe = 0;
1215  sti->need_parsing = need_parsing;
1216 
1219 
1220  return 0;
1221 }
1222 
1224 {
1225  DVDVideoDemuxContext *c = s->priv_data;
1226 
1227  int ret;
1228  int nb_streams;
1229 
1230  if (c->opt_menu)
1231  nb_streams = !c->opt_menu_vts ? c->vmg_ifo->vmgi_mat->nr_of_vmgm_audio_streams :
1232  c->vts_ifo->vtsi_mat->nr_of_vtsm_audio_streams;
1233  else
1234  nb_streams = c->vts_ifo->vtsi_mat->nr_of_vts_audio_streams;
1235 
1236  for (int i = 0; i < nb_streams; i++) {
1238  audio_attr_t audio_attr;
1239 
1240  if (c->opt_menu)
1241  audio_attr = !c->opt_menu_vts ? c->vmg_ifo->vmgi_mat->vmgm_audio_attr :
1242  c->vts_ifo->vtsi_mat->vtsm_audio_attr;
1243  else
1244  audio_attr = c->vts_ifo->vtsi_mat->vts_audio_attr[i];
1245 
1246  if (!(c->play_state.pgc->audio_control[i] & 0x8000))
1247  continue;
1248 
1249  if ((ret = dvdvideo_audio_stream_analyze(s, audio_attr, c->play_state.pgc->audio_control[i],
1250  &entry)) < 0)
1251  goto break_error;
1252 
1253  /* IFO structures can declare duplicate entries for the same startcode */
1254  for (int j = 0; j < s->nb_streams; j++)
1255  if (s->streams[j]->id == entry.startcode)
1256  continue;
1257 
1259  goto break_error;
1260 
1261  continue;
1262 
1263 break_error:
1264  av_log(s, AV_LOG_ERROR, "Unable to add audio stream at position %d\n", i);
1265  return ret;
1266  }
1267 
1268  return 0;
1269 }
1270 
1271 static int dvdvideo_subp_stream_analyze(AVFormatContext *s, uint32_t offset, subp_attr_t subp_attr,
1273 {
1274  DVDVideoDemuxContext *c = s->priv_data;
1275 
1276  char lang_dvd[3] = {0};
1277 
1278  entry->startcode = 0x20 + (offset & 0x1F);
1279 
1280  if (subp_attr.lang_extension == 9)
1281  entry->disposition |= AV_DISPOSITION_FORCED;
1282 
1283  memcpy(&entry->clut, c->play_state.pgc->palette, FF_DVDCLUT_CLUT_SIZE);
1284 
1285  /* dvdsub palettes currently have no colorspace tagging and all muxers only support RGB */
1286  /* this is not a lossless conversion, but no use cases are supported for the original YUV */
1288 
1289  AV_WB16(lang_dvd, subp_attr.lang_code);
1290  entry->lang_iso = ff_convert_lang_to(lang_dvd, AV_LANG_ISO639_2_BIBL);
1291 
1292  return 0;
1293 }
1294 
1296  enum AVStreamParseType need_parsing)
1297 {
1298  AVStream *st;
1299  FFStream *sti;
1300  int ret;
1301 
1302  st = avformat_new_stream(s, NULL);
1303  if (!st)
1304  return AVERROR(ENOMEM);
1305 
1306  st->id = entry->startcode;
1309 
1311  return ret;
1312 
1313  if (entry->lang_iso)
1314  av_dict_set(&st->metadata, "language", entry->lang_iso, 0);
1315 
1316  av_dict_set(&st->metadata, "VIEWPORT", dvdvideo_subp_viewport_labels[entry->viewport], 0);
1317 
1318  st->disposition = entry->disposition;
1319 
1320  sti = ffstream(st);
1321  sti->request_probe = 0;
1322  sti->need_parsing = need_parsing;
1323 
1326 
1327  return 0;
1328 }
1329 
1331  subp_attr_t subp_attr,
1332  enum DVDVideoSubpictureViewport viewport)
1333 {
1334  int ret;
1336 
1337  entry.viewport = viewport;
1338 
1339  if ((ret = dvdvideo_subp_stream_analyze(s, offset, subp_attr, &entry)) < 0)
1340  goto end_error;
1341 
1342  /* IFO structures can declare duplicate entries for the same startcode */
1343  for (int i = 0; i < s->nb_streams; i++)
1344  if (s->streams[i]->id == entry.startcode)
1345  return 0;
1346 
1348  goto end_error;
1349 
1350  return 0;
1351 
1352 end_error:
1353  av_log(s, AV_LOG_ERROR, "Unable to add subtitle stream\n");
1354  return ret;
1355 }
1356 
1358 {
1359  DVDVideoDemuxContext *c = s->priv_data;
1360 
1361  int nb_streams;
1362 
1363  if (c->opt_menu)
1364  nb_streams = !c->opt_menu_vts ? c->vmg_ifo->vmgi_mat->nr_of_vmgm_subp_streams :
1365  c->vts_ifo->vtsi_mat->nr_of_vtsm_subp_streams;
1366  else
1367  nb_streams = c->vts_ifo->vtsi_mat->nr_of_vts_subp_streams;
1368 
1369 
1370  for (int i = 0; i < nb_streams; i++) {
1371  int ret;
1372  uint32_t subp_control;
1373  subp_attr_t subp_attr;
1374  video_attr_t video_attr;
1375 
1376  subp_control = c->play_state.pgc->subp_control[i];
1377  if (!(subp_control & 0x80000000))
1378  continue;
1379 
1380  /* there can be several presentations for one SPU */
1381  /* the DAR check is flexible in order to support weird authoring */
1382  if (c->opt_menu) {
1383  video_attr = !c->opt_menu_vts ? c->vmg_ifo->vmgi_mat->vmgm_video_attr :
1384  c->vts_ifo->vtsi_mat->vtsm_video_attr;
1385 
1386  subp_attr = !c->opt_menu_vts ? c->vmg_ifo->vmgi_mat->vmgm_subp_attr :
1387  c->vts_ifo->vtsi_mat->vtsm_subp_attr;
1388  } else {
1389  video_attr = c->vts_ifo->vtsi_mat->vts_video_attr;
1390  subp_attr = c->vts_ifo->vtsi_mat->vts_subp_attr[i];
1391  }
1392 
1393  /* 4:3 */
1394  if (!video_attr.display_aspect_ratio) {
1395  if ((ret = dvdvideo_subp_stream_add_internal(s, subp_control >> 24, subp_attr,
1397  return ret;
1398 
1399  continue;
1400  }
1401 
1402  /* 16:9 */
1403  if (( ret = dvdvideo_subp_stream_add_internal(s, subp_control >> 16, subp_attr,
1405  return ret;
1406 
1407  /* 16:9 letterbox */
1408  if (video_attr.permitted_df == 2 || video_attr.permitted_df == 0)
1409  if ((ret = dvdvideo_subp_stream_add_internal(s, subp_control >> 8, subp_attr,
1411  return ret;
1412 
1413  /* 16:9 pan-and-scan */
1414  if (video_attr.permitted_df == 1 || video_attr.permitted_df == 0)
1415  if ((ret = dvdvideo_subp_stream_add_internal(s, subp_control, subp_attr,
1417  return ret;
1418  }
1419 
1420  return 0;
1421 }
1422 
1424 {
1425  DVDVideoDemuxContext *c = s->priv_data;
1426 
1427  if (!c->segment_started)
1428  return;
1429 
1430  av_log(s, AV_LOG_DEBUG, "flushing sub-demuxer\n");
1431  avio_flush(&c->mpeg_pb.pub);
1432  ff_read_frame_flush(c->mpeg_ctx);
1433  c->segment_started = 0;
1434 }
1435 
1436 static int dvdvideo_subdemux_read_data(void *opaque, uint8_t *buf, int buf_size)
1437 {
1438  AVFormatContext *s = opaque;
1439  DVDVideoDemuxContext *c = s->priv_data;
1440 
1441  int ret = 0;
1442  int nav_event;
1443 
1444  if (c->play_end)
1445  return AVERROR_EOF;
1446 
1447  if (c->opt_menu)
1448  ret = dvdvideo_menu_next_ps_block(s, &c->play_state, buf, buf_size,
1450  else
1451  ret = dvdvideo_play_next_ps_block(opaque, &c->play_state, buf, buf_size,
1452  &nav_event, dvdvideo_subdemux_flush);
1453 
1454  if (ret == AVERROR_EOF) {
1455  c->mpeg_pb.pub.eof_reached = 1;
1456  c->play_end = 1;
1457 
1458  return AVERROR_EOF;
1459  }
1460 
1461  if (ret >= 0 && nav_event == DVDNAV_NAV_PACKET)
1462  return FFERROR_REDO;
1463 
1464  return ret;
1465 }
1466 
1468 {
1469  DVDVideoDemuxContext *c = s->priv_data;
1470 
1471  av_freep(&c->mpeg_pb.pub.buffer);
1472  avformat_close_input(&c->mpeg_ctx);
1473 }
1474 
1476 {
1477  DVDVideoDemuxContext *c = s->priv_data;
1478  extern const FFInputFormat ff_mpegps_demuxer;
1479  int ret;
1480 
1481  if (!(c->mpeg_buf = av_mallocz(DVDVIDEO_BLOCK_SIZE)))
1482  return AVERROR(ENOMEM);
1483 
1484  ffio_init_context(&c->mpeg_pb, c->mpeg_buf, DVDVIDEO_BLOCK_SIZE, 0, s,
1486  c->mpeg_pb.pub.seekable = 0;
1487 
1488  if (!(c->mpeg_ctx = avformat_alloc_context()))
1489  return AVERROR(ENOMEM);
1490 
1491  if ((ret = ff_copy_whiteblacklists(c->mpeg_ctx, s)) < 0) {
1492  avformat_free_context(c->mpeg_ctx);
1493  c->mpeg_ctx = NULL;
1494 
1495  return ret;
1496  }
1497 
1498  c->mpeg_ctx->flags = AVFMT_FLAG_CUSTOM_IO | AVFMT_FLAG_GENPTS;
1499  c->mpeg_ctx->ctx_flags |= AVFMTCTX_UNSEEKABLE;
1500  c->mpeg_ctx->probesize = 0;
1501  c->mpeg_ctx->max_analyze_duration = 0;
1502  c->mpeg_ctx->interrupt_callback = s->interrupt_callback;
1503  c->mpeg_ctx->pb = &c->mpeg_pb.pub;
1504  c->mpeg_ctx->correct_ts_overflow = 0;
1505  c->mpeg_ctx->io_open = NULL;
1506 
1507  return avformat_open_input(&c->mpeg_ctx, "", &ff_mpegps_demuxer.p, NULL);
1508 }
1509 
1511 {
1512  DVDVideoDemuxContext *c = s->priv_data;
1513 
1514  int ret;
1515 
1516  if (c->opt_menu) {
1517  if (c->opt_region ||
1518  c->opt_title > 1 ||
1519  c->opt_preindex ||
1520  c->opt_chapter_start > 1 ||
1521  c->opt_chapter_end > 0) {
1522  av_log(s, AV_LOG_ERROR, "-menu is not compatible with the -region, -title, "
1523  "-preindex, or -chapter_start/-chapter_end options\n");
1524  return AVERROR(EINVAL);
1525  }
1526 
1527  if (!c->opt_pgc) {
1528  av_log(s, AV_LOG_ERROR, "If -menu is enabled, -pgc must be set to a non-zero value\n");
1529 
1530  return AVERROR(EINVAL);
1531  }
1532 
1533  if (!c->opt_menu_lu) {
1534  av_log(s, AV_LOG_INFO, "Defaulting to menu language unit #1. "
1535  "This is not always desirable, validation suggested.\n");
1536 
1537  c->opt_menu_lu = 1;
1538  }
1539 
1540  if (!c->opt_pg) {
1541  av_log(s, AV_LOG_INFO, "Defaulting to menu PG #1. "
1542  "This is not always desirable, validation suggested.\n");
1543 
1544  c->opt_pg = 1;
1545  }
1546 
1547  if ((ret = dvdvideo_ifo_open(s)) < 0 ||
1548  (ret = dvdvideo_menu_open(s, &c->play_state)) < 0 ||
1549  (ret = dvdvideo_subdemux_open(s)) < 0 ||
1550  (ret = dvdvideo_video_stream_setup(s)) < 0 ||
1552  return ret;
1553 
1554  return 0;
1555  }
1556 
1557  if (c->opt_chapter_end != 0 && c->opt_chapter_start > c->opt_chapter_end) {
1558  av_log(s, AV_LOG_ERROR, "Chapter (PTT) range [%d, %d] is invalid\n",
1559  c->opt_chapter_start, c->opt_chapter_end);
1560 
1561  return AVERROR(EINVAL);
1562  }
1563 
1564  if (c->opt_title == 0) {
1565  av_log(s, AV_LOG_INFO, "Defaulting to title #1. "
1566  "This is not always the main feature, validation suggested.\n");
1567 
1568  c->opt_title = 1;
1569  }
1570 
1571  if (c->opt_pgc) {
1572  if (c->opt_pg == 0) {
1573  av_log(s, AV_LOG_ERROR, "Invalid coordinates. If -pgc is set, -pg must be set too.\n");
1574 
1575  return AVERROR(EINVAL);
1576  } else if (c->opt_chapter_start > 1 || c->opt_chapter_end > 0 || c->opt_preindex) {
1577  av_log(s, AV_LOG_ERROR, "-pgc is not compatible with the -preindex or "
1578  "-chapter_start/-chapter_end options\n");
1579  return AVERROR(EINVAL);
1580  }
1581  }
1582 
1583  if ((ret = dvdvideo_ifo_open(s)) < 0)
1584  return ret;
1585 
1586  if (!c->opt_pgc && c->opt_preindex && (ret = dvdvideo_chapters_setup_preindex(s)) < 0)
1587  return ret;
1588 
1589  if ((ret = dvdvideo_play_open(s, &c->play_state)) < 0 ||
1590  (ret = dvdvideo_subdemux_open(s)) < 0 ||
1591  (ret = dvdvideo_video_stream_setup(s)) < 0 ||
1592  (ret = dvdvideo_audio_stream_add_all(s)) < 0 ||
1594  return ret;
1595 
1596  if (!c->opt_pgc && !c->opt_preindex)
1598 
1599  return 0;
1600 }
1601 
1603 {
1604  DVDVideoDemuxContext *c = s->priv_data;
1605 
1606  int ret;
1607  enum AVMediaType st_type;
1608  int found_stream = 0;
1609 
1610  if (c->play_end)
1611  return AVERROR_EOF;
1612 
1613  ret = av_read_frame(c->mpeg_ctx, pkt);
1614 
1615  if (ret < 0)
1616  return ret;
1617 
1618  if (!c->segment_started)
1619  c->segment_started = 1;
1620 
1621  st_type = c->mpeg_ctx->streams[pkt->stream_index]->codecpar->codec_type;
1622 
1623  /* map the subdemuxer stream to the parent demuxer's stream (by startcode) */
1624  for (int i = 0; i < s->nb_streams; i++) {
1625  if (s->streams[i]->id == c->mpeg_ctx->streams[pkt->stream_index]->id) {
1626  pkt->stream_index = s->streams[i]->index;
1627  found_stream = 1;
1628  break;
1629  }
1630  }
1631 
1632  if (!found_stream) {
1633  av_log(s, AV_LOG_DEBUG, "discarding frame with stream that was not in IFO headers "
1634  "(stream id=%d)\n", c->mpeg_ctx->streams[pkt->stream_index]->id);
1635 
1636  return FFERROR_REDO;
1637  }
1638 
1639  if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE) {
1640  if (!c->play_started) {
1641  /* try to start at the beginning of a GOP */
1642  if (st_type != AVMEDIA_TYPE_VIDEO || !(pkt->flags & AV_PKT_FLAG_KEY)) {
1643  av_log(s, AV_LOG_VERBOSE, "Discarding packet which is not a video keyframe or "
1644  "with unset PTS/DTS at start\n");
1645  return FFERROR_REDO;
1646  }
1647 
1648  c->first_pts = pkt->pts;
1649  c->play_started = 1;
1650  }
1651 
1652  pkt->pts += c->play_state.ts_offset - c->first_pts;
1653  pkt->dts += c->play_state.ts_offset - c->first_pts;
1654 
1655  if (pkt->pts < 0) {
1656  av_log(s, AV_LOG_VERBOSE, "Discarding packet with negative PTS (st=%d pts=%" PRId64 "), "
1657  "this is OK at start of playback\n",
1658  pkt->stream_index, pkt->pts);
1659 
1660  return FFERROR_REDO;
1661  }
1662  } else {
1663  av_log(s, AV_LOG_WARNING, "Unset PTS or DTS @ st=%d pts=%" PRId64 " dts=%" PRId64 "\n",
1664  pkt->stream_index, pkt->pts, pkt->dts);
1665  }
1666 
1667  av_log(s, AV_LOG_TRACE, "st=%d pts=%" PRId64 " dts=%" PRId64 " "
1668  "ts_offset=%" PRId64 " first_pts=%" PRId64 "\n",
1669  pkt->stream_index, pkt->pts, pkt->dts,
1670  c->play_state.ts_offset, c->first_pts);
1671 
1672  return c->play_end ? AVERROR_EOF : 0;
1673 }
1674 
1676 {
1677  DVDVideoDemuxContext *c = s->priv_data;
1678 
1680 
1681  if (c->opt_menu)
1682  dvdvideo_menu_close(s, &c->play_state);
1683  else
1684  dvdvideo_play_close(s, &c->play_state);
1685 
1687 
1688  return 0;
1689 }
1690 
1691 #define OFFSET(x) offsetof(DVDVideoDemuxContext, x)
1692 static const AVOption dvdvideo_options[] = {
1693  {"angle", "playback angle number", OFFSET(opt_angle), AV_OPT_TYPE_INT, { .i64=1 }, 1, 9, AV_OPT_FLAG_DECODING_PARAM },
1694  {"chapter_end", "exit chapter (PTT) number (0=end)", OFFSET(opt_chapter_end), AV_OPT_TYPE_INT, { .i64=0 }, 0, 99, AV_OPT_FLAG_DECODING_PARAM },
1695  {"chapter_start", "entry chapter (PTT) number", OFFSET(opt_chapter_start), AV_OPT_TYPE_INT, { .i64=1 }, 1, 99, AV_OPT_FLAG_DECODING_PARAM },
1696  {"menu", "demux menu domain", OFFSET(opt_menu), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1697  {"menu_lu", "menu language unit (0=auto)", OFFSET(opt_menu_lu), AV_OPT_TYPE_INT, { .i64=0 }, 0, 99, AV_OPT_FLAG_DECODING_PARAM },
1698  {"menu_vts", "menu VTS (0=VMG main menu)", OFFSET(opt_menu_vts), AV_OPT_TYPE_INT, { .i64=0 }, 0, 99, AV_OPT_FLAG_DECODING_PARAM },
1699  {"pg", "entry PG number (0=auto)", OFFSET(opt_pg), AV_OPT_TYPE_INT, { .i64=0 }, 0, 255, AV_OPT_FLAG_DECODING_PARAM },
1700  {"pgc", "entry PGC number (0=auto)", OFFSET(opt_pgc), AV_OPT_TYPE_INT, { .i64=0 }, 0, 999, AV_OPT_FLAG_DECODING_PARAM },
1701  {"preindex", "enable for accurate chapter markers, slow (2-pass read)", OFFSET(opt_preindex), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1702  {"region", "playback region number (0=free)", OFFSET(opt_region), AV_OPT_TYPE_INT, { .i64=0 }, 0, 8, AV_OPT_FLAG_DECODING_PARAM },
1703  {"title", "title number (0=auto)", OFFSET(opt_title), AV_OPT_TYPE_INT, { .i64=0 }, 0, 99, AV_OPT_FLAG_DECODING_PARAM },
1704  {"trim", "trim padding cells from start", OFFSET(opt_trim), AV_OPT_TYPE_BOOL, { .i64=1 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
1705  {NULL}
1706 };
1707 
1708 static const AVClass dvdvideo_class = {
1709  .class_name = "DVD-Video demuxer",
1710  .item_name = av_default_item_name,
1711  .option = dvdvideo_options,
1712  .version = LIBAVUTIL_VERSION_INT
1713 };
1714 
1716  .p.name = "dvdvideo",
1717  .p.long_name = NULL_IF_CONFIG_SMALL("DVD-Video"),
1718  .p.priv_class = &dvdvideo_class,
1721  .priv_data_size = sizeof(DVDVideoDemuxContext),
1722  .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
1726 };
avpriv_new_chapter
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: demux_utils.c:42
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
dvdvideo_subp_stream_analyze
static int dvdvideo_subp_stream_analyze(AVFormatContext *s, uint32_t offset, subp_attr_t subp_attr, DVDVideoPGCSubtitleStreamEntry *entry)
Definition: dvdvideodec.c:1271
state
static struct @449 state
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
entry
#define entry
Definition: aom_film_grain_template.c:66
AVFMT_NO_BYTE_SEEK
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition: avformat.h:487
level
uint8_t level
Definition: svq3.c:205
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:443
ffio_init_context
void ffio_init_context(FFIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:50
DVDVIDEO_MAX_PS_SEARCH_BLOCKS
#define DVDVIDEO_MAX_PS_SEARCH_BLOCKS
Definition: dvdvideodec.c:58
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
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AVFMT_SHOW_IDS
#define AVFMT_SHOW_IDS
Show format stream IDs numbers.
Definition: avformat.h:477
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:387
DVDVideoPGCAudioStreamEntry::ch_layout
AVChannelLayout ch_layout
Definition: dvdvideodec.c:94
dvdvideo_is_pgc_promising
static int dvdvideo_is_pgc_promising(AVFormatContext *s, pgc_t *pgc)
Definition: dvdvideodec.c:308
DVDVideoVTSVideoStreamEntry::width
int width
Definition: dvdvideodec.c:80
DVDVideoDemuxContext::opt_region
int opt_region
Definition: dvdvideodec.c:151
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
dvdvideo_play_open
static int dvdvideo_play_open(AVFormatContext *s, DVDVideoPlaybackState *state)
Definition: dvdvideodec.c:508
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
int64_t
long long int64_t
Definition: coverity.c:34
DVDVideoVTSVideoStreamEntry::height
int height
Definition: dvdvideodec.c:81
avlanguage.h
DVDVideoVTSVideoStreamEntry::codec_id
enum AVCodecID codec_id
Definition: dvdvideodec.c:79
DVDVideoVTSVideoStreamEntry::framerate
AVRational framerate
Definition: dvdvideodec.c:83
DVDVideoDemuxContext::opt_trim
int opt_trim
Definition: dvdvideodec.c:153
dvdvideo_audio_stream_analyze
static int dvdvideo_audio_stream_analyze(AVFormatContext *s, audio_attr_t audio_attr, uint16_t audio_control, DVDVideoPGCAudioStreamEntry *entry)
Definition: dvdvideodec.c:1086
DVDVideoDemuxContext::vts_ifo
ifo_handle_t * vts_ifo
Definition: dvdvideodec.c:163
dvdvideo_play_close
static void dvdvideo_play_close(AVFormatContext *s, DVDVideoPlaybackState *state)
Definition: dvdvideodec.c:494
OFFSET
#define OFFSET(x)
Definition: dvdvideodec.c:1691
AVOption
AVOption.
Definition: opt.h:429
DVDVideoPlaybackState::celln
int celln
Definition: dvdvideodec.c:108
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:837
AVFMT_FLAG_CUSTOM_IO
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition: avformat.h:1419
DVDVideoPlaybackState::vtsn
int vtsn
Definition: dvdvideodec.c:123
DVDVideoVTSVideoStreamEntry::has_cc
int has_cc
Definition: dvdvideodec.c:84
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
DVDVideoPlaybackState::pgc_duration_est
uint64_t pgc_duration_est
Definition: dvdvideodec.c:114
DVDVideoPlaybackState::pgcn
int pgcn
Definition: dvdvideodec.c:117
DVDVideoPGCAudioStreamEntry::bit_depth
int bit_depth
Definition: dvdvideodec.c:92
DVDVideoPlaybackState::vobu_next
uint32_t vobu_next
Definition: dvdvideodec.c:133
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1538
AVFMT_NOBINSEARCH
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:485
DVDVideoDemuxContext::first_pts
int64_t first_pts
Definition: dvdvideodec.c:166
DVDVideoPlaybackState::in_vts
int in_vts
Definition: dvdvideodec.c:112
DVDVideoDemuxContext::dvdread
dvd_reader_t * dvdread
Definition: dvdvideodec.c:161
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:321
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
ff_read_frame_flush
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
Definition: seek.c:721
ff_dvdclut_yuv_to_rgb
int ff_dvdclut_yuv_to_rgb(uint32_t *clut, const size_t clut_size)
Definition: dvdclut.c:50
FFIOContext
Definition: avio_internal.h:28
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:588
DVDVideoPGCSubtitleStreamEntry::lang_iso
const char * lang_iso
Definition: dvdvideodec.c:104
DVDVideoPlaybackState::in_ps
int in_ps
Definition: dvdvideodec.c:111
DVDVideoPlaybackState::vobu_duration
uint32_t vobu_duration
Definition: dvdvideodec.c:121
DVDVideoPGCSubtitleStreamEntry::disposition
int disposition
Definition: dvdvideodec.c:102
DVDVideoDemuxContext::vmg_ifo
ifo_handle_t * vmg_ifo
Definition: dvdvideodec.c:162
dvdvideo_ifo_open
static int dvdvideo_ifo_open(AVFormatContext *s)
Definition: dvdvideodec.c:222
DVDVideoDemuxContext::mpeg_pb
FFIOContext mpeg_pb
Definition: dvdvideodec.c:158
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:363
DVDVideoDemuxContext
Definition: dvdvideodec.c:138
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:855
FF_DVDCLUT_CLUT_LEN
#define FF_DVDCLUT_CLUT_LEN
Definition: dvdclut.h:28
dvdvideo_subdemux_read_data
static int dvdvideo_subdemux_read_data(void *opaque, uint8_t *buf, int buf_size)
Definition: dvdvideodec.c:1436
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:419
DVDVideoPlaybackState::vobu_e_ptm
uint32_t vobu_e_ptm
Definition: dvdvideodec.c:122
AVCodecParameters::bits_per_raw_sample
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: codec_par.h:123
FF_DVDCLUT_CLUT_SIZE
#define FF_DVDCLUT_CLUT_SIZE
Definition: dvdclut.h:29
samplefmt.h
AVStreamParseType
AVStreamParseType
Definition: avformat.h:591
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:143
DVDVideoPlaybackState::sector_offset
int sector_offset
Definition: dvdvideodec.c:131
AV_DISPOSITION_FORCED
#define AV_DISPOSITION_FORCED
Track should be used during playback by default.
Definition: avformat.h:654
ff_check_interrupt
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:854
DVDVideoVTSVideoStreamEntry::dar
AVRational dar
Definition: dvdvideodec.c:82
dvdvideo_play_next_ps_block
static int dvdvideo_play_next_ps_block(AVFormatContext *s, DVDVideoPlaybackState *state, uint8_t *buf, int buf_size, int *p_nav_event, void(*flush_cb)(AVFormatContext *s))
Definition: dvdvideodec.c:612
DVDVideoPGCAudioStreamEntry::sample_fmt
int sample_fmt
Definition: dvdvideodec.c:90
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
DVDVideoPlaybackState::vobu_remaining
uint32_t vobu_remaining
Definition: dvdvideodec.c:134
DVDVideoDemuxContext::opt_chapter_start
int opt_chapter_start
Definition: dvdvideodec.c:144
DVDVideoPlaybackState::celln_end
int celln_end
Definition: dvdvideodec.c:130
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:215
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:42
DVDVideoPGCAudioStreamEntry::startcode
int startcode
Definition: dvdvideodec.c:88
DVDVideoPlaybackState::dvdnav
dvdnav_t * dvdnav
Definition: dvdvideodec.c:126
DVDVideoDemuxContext::segment_started
int segment_started
Definition: dvdvideodec.c:170
width
#define width
AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_7POINT1
Definition: channel_layout.h:409
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
dvdvideo_video_stream_analyze
static int dvdvideo_video_stream_analyze(AVFormatContext *s, video_attr_t video_attr, DVDVideoVTSVideoStreamEntry *entry)
Definition: dvdvideodec.c:978
dvdvideo_video_stream_setup
static int dvdvideo_video_stream_setup(AVFormatContext *s)
Definition: dvdvideodec.c:1062
dvdvideo_subp_viewport_labels
static const char dvdvideo_subp_viewport_labels[4][13]
Definition: dvdvideodec.c:73
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
dvdvideo_chapters_setup_simple
static int dvdvideo_chapters_setup_simple(AVFormatContext *s)
Definition: dvdvideodec.c:855
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:440
DVDVideoDemuxContext::opt_menu_lu
int opt_menu_lu
Definition: dvdvideodec.c:146
dvdvideo_libdvdread_log
static void dvdvideo_libdvdread_log(void *opaque, dvd_logger_level_t level, const char *msg, va_list msg_va)
Definition: dvdvideodec.c:173
AVERROR_INPUT_CHANGED
#define AVERROR_INPUT_CHANGED
Input changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_OUTPUT_CHANGED)
Definition: error.h:75
DVDVideoVTSVideoStreamEntry
Definition: dvdvideodec.c:77
dvdvideo_read_header
static int dvdvideo_read_header(AVFormatContext *s)
Definition: dvdvideodec.c:1510
dvdclut.h
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
DVDVideoPGCSubtitleStreamEntry
Definition: dvdvideodec.c:99
DVDVideoPlaybackState::ts_offset
int64_t ts_offset
Definition: dvdvideodec.c:120
DVDVideoPlaybackState::ptt
int ptt
Definition: dvdvideodec.c:119
nb_streams
static int nb_streams
Definition: ffprobe.c:384
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
FFStream::display_aspect_ratio
AVRational display_aspect_ratio
display aspect ratio (0 if unknown)
Definition: internal.h:368
DVDVideoPlaybackState::pgc
pgc_t * pgc
Definition: dvdvideodec.c:125
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:394
AV_CODEC_ID_PCM_DVD
@ AV_CODEC_ID_PCM_DVD
Definition: codec_id.h:347
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
DVDVideoPlaybackState::sector_end
uint32_t sector_end
Definition: dvdvideodec.c:132
DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE
#define DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE
Definition: dvdvideodec.c:62
dvdvideo_chapters_setup_preindex
static int dvdvideo_chapters_setup_preindex(AVFormatContext *s)
Definition: dvdvideodec.c:901
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:223
FF_INFMT_FLAG_INIT_CLEANUP
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition: demux.h:35
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:386
AVFormatContext
Format I/O context.
Definition: avformat.h:1260
DVDVideoDemuxContext::opt_angle
int opt_angle
Definition: dvdvideodec.c:142
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
AV_LANG_ISO639_2_BIBL
@ AV_LANG_ISO639_2_BIBL
Definition: avlanguage.h:28
framerate
float framerate
Definition: av1_levels.c:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:535
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
DVDVideoPlaybackState::celln_start
int celln_start
Definition: dvdvideodec.c:129
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
dvdvideo_class
static const AVClass dvdvideo_class
Definition: dvdvideodec.c:1708
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:401
DVDVideoDemuxContext::play_end
int play_end
Definition: dvdvideodec.c:167
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVFMTCTX_UNSEEKABLE
#define AVFMTCTX_UNSEEKABLE
signal that the stream is definitely not seekable, and attempts to call the seek function will fail.
Definition: avformat.h:1213
DVDVideoDemuxContext::mpeg_buf
uint8_t * mpeg_buf
Definition: dvdvideodec.c:157
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: avformat.c:900
DVDVideoPlaybackState::pgn
int pgn
Definition: dvdvideodec.c:118
dvdvideo_read_packet
static int dvdvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dvdvideodec.c:1602
AV_DISPOSITION_COMMENT
#define AV_DISPOSITION_COMMENT
The stream is a commentary track.
Definition: avformat.h:639
AV_CODEC_ID_DVD_SUBTITLE
@ AV_CODEC_ID_DVD_SUBTITLE
Definition: codec_id.h:550
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:828
dvdvideo_close
static int dvdvideo_close(AVFormatContext *s)
Definition: dvdvideodec.c:1675
DVDVideoPGCAudioStreamEntry::disposition
int disposition
Definition: dvdvideodec.c:95
time.h
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
dvdvideo_libdvdnav_log
static void dvdvideo_libdvdnav_log(void *opaque, dvdnav_logger_level_t level, const char *msg, va_list msg_va)
Definition: dvdvideodec.c:190
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
dvdvideo_subdemux_close
static void dvdvideo_subdemux_close(AVFormatContext *s)
Definition: dvdvideodec.c:1467
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
dvdvideo_audio_stream_add_all
static int dvdvideo_audio_stream_add_all(AVFormatContext *s)
Definition: dvdvideodec.c:1223
dvdvideo_menu_close
static void dvdvideo_menu_close(AVFormatContext *s, DVDVideoPlaybackState *state)
Definition: dvdvideodec.c:317
DVDVideoDemuxContext::play_state
DVDVideoPlaybackState play_state
Definition: dvdvideodec.c:168
DVDVideoDemuxContext::opt_menu
int opt_menu
Definition: dvdvideodec.c:145
DVDVideoDemuxContext::opt_menu_vts
int opt_menu_vts
Definition: dvdvideodec.c:147
DVDVideoPlaybackState::nav_pts
int64_t nav_pts
Definition: dvdvideodec.c:113
DVDVideoPGCSubtitleStreamEntry::clut
uint32_t clut[FF_DVDCLUT_CLUT_LEN]
Definition: dvdvideodec.c:103
AVMediaType
AVMediaType
Definition: avutil.h:199
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:161
DVDVideoPGCAudioStreamEntry::codec_id
enum AVCodecID codec_id
Definition: dvdvideodec.c:89
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:311
FFStream
Definition: internal.h:193
ff_convert_lang_to
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:741
ff_dvdclut_palette_extradata_cat
int ff_dvdclut_palette_extradata_cat(const uint32_t *clut, const size_t clut_size, AVCodecParameters *par)
Definition: dvdclut.c:28
AV_CODEC_ID_DTS
@ AV_CODEC_ID_DTS
Definition: codec_id.h:444
DVDVideoPlaybackState::pgc_nb_pg_est
int pgc_nb_pg_est
Definition: dvdvideodec.c:116
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
DVDVideoPGCSubtitleStreamEntry::startcode
int startcode
Definition: dvdvideodec.c:100
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
DVDVideoPGCSubtitleStreamEntry::viewport
enum DVDVideoSubpictureViewport viewport
Definition: dvdvideodec.c:101
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
DVDVideoDemuxContext::opt_pg
int opt_pg
Definition: dvdvideodec.c:148
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:41
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:532
height
#define height
dvdvideo_ifo_close
static void dvdvideo_ifo_close(AVFormatContext *s)
Definition: dvdvideodec.c:208
DVDVideoSubpictureViewport
DVDVideoSubpictureViewport
Definition: dvdvideodec.c:67
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:539
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
DVDVideoDemuxContext::mpeg_ctx
AVFormatContext * mpeg_ctx
Definition: dvdvideodec.c:156
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
FFERROR_REDO
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition: demux.h:171
DVDVideoDemuxContext::opt_pgc
int opt_pgc
Definition: dvdvideodec.c:149
DVDVIDEO_BLOCK_SIZE
#define DVDVIDEO_BLOCK_SIZE
Definition: dvdvideodec.c:59
DVDVIDEO_PTS_WRAP_BITS
#define DVDVIDEO_PTS_WRAP_BITS
Definition: dvdvideodec.c:61
dvdvideo_video_stream_add
static int dvdvideo_video_stream_add(AVFormatContext *s, DVDVideoVTSVideoStreamEntry *entry, enum AVStreamParseType need_parsing)
Definition: dvdvideodec.c:1027
DVDVIDEO_SUBP_VIEWPORT_PANSCAN
@ DVDVIDEO_SUBP_VIEWPORT_PANSCAN
Definition: dvdvideodec.c:71
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:526
dvdvideo_menu_open
static int dvdvideo_menu_open(AVFormatContext *s, DVDVideoPlaybackState *state)
Definition: dvdvideodec.c:323
avio_internal.h
dvdvideo_subp_stream_add
static int dvdvideo_subp_stream_add(AVFormatContext *s, DVDVideoPGCSubtitleStreamEntry *entry, enum AVStreamParseType need_parsing)
Definition: dvdvideodec.c:1295
DVDVideoDemuxContext::opt_chapter_end
int opt_chapter_end
Definition: dvdvideodec.c:143
DVDVideoVTSVideoStreamEntry::startcode
int startcode
Definition: dvdvideodec.c:78
AVCodecParameters::height
int height
Definition: codec_par.h:135
DVDVideoPlaybackState::entry_pgn
int entry_pgn
Definition: dvdvideodec.c:109
vsnprintf
#define vsnprintf
Definition: snprintf.h:36
AV_DISPOSITION_KARAOKE
#define AV_DISPOSITION_KARAOKE
The stream contains karaoke audio.
Definition: avformat.h:647
url.h
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
DVDVideoPlaybackState::in_pgc
int in_pgc
Definition: dvdvideodec.c:110
ff_dvdvideo_demuxer
const FFInputFormat ff_dvdvideo_demuxer
Definition: dvdvideodec.c:1715
demux.h
DVDVIDEO_SUBP_VIEWPORT_LETTERBOX
@ DVDVIDEO_SUBP_VIEWPORT_LETTERBOX
Definition: dvdvideodec.c:70
AVCodecParameters::color_range
enum AVColorRange color_range
Video only.
Definition: codec_par.h:166
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:669
dvdvideo_is_cell_promising
static int dvdvideo_is_cell_promising(AVFormatContext *s, pgc_t *pgc, int celln)
Definition: dvdvideodec.c:301
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:817
AVFMT_FLAG_GENPTS
#define AVFMT_FLAG_GENPTS
Generate missing pts even if it requires parsing future frames.
Definition: avformat.h:1412
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:662
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:760
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
DVDVideoPlaybackState::pgc_pg_times_est
uint64_t * pgc_pg_times_est
Definition: dvdvideodec.c:124
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:71
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:594
avformat.h
PCI_START_BYTE
#define PCI_START_BYTE
Definition: dvdvideodec.c:64
dvdvideo_options
static const AVOption dvdvideo_options[]
Definition: dvdvideodec.c:1692
AVERROR_STREAM_NOT_FOUND
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
Definition: error.h:67
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:141
AVFMT_NOGENSEARCH
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition: avformat.h:486
ff_mpegps_demuxer
const FFInputFormat ff_mpegps_demuxer
Definition: mpeg.c:701
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:914
dvdvideo_subdemux_flush
static void dvdvideo_subdemux_flush(AVFormatContext *s)
Definition: dvdvideodec.c:1423
AVPacket::stream_index
int stream_index
Definition: packet.h:535
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
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avutil.h
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:481
mem.h
DVDVideoDemuxContext::opt_title
int opt_title
Definition: dvdvideodec.c:152
AVCodecParameters::format
int format
Definition: codec_par.h:92
dvdvideo_subdemux_open
static int dvdvideo_subdemux_open(AVFormatContext *s)
Definition: dvdvideodec.c:1475
DVDVideoPGCAudioStreamEntry::nb_channels
int nb_channels
Definition: dvdvideodec.c:93
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:386
FFStream::request_probe
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: internal.h:263
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
dvdvideo_audio_stream_add
static int dvdvideo_audio_stream_add(AVFormatContext *s, DVDVideoPGCAudioStreamEntry *entry, enum AVStreamParseType need_parsing)
Definition: dvdvideodec.c:1189
AVPacket
This structure stores compressed data.
Definition: packet.h:510
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
FFInputFormat
Definition: demux.h:37
dvdvideo_subp_stream_add_all
static int dvdvideo_subp_stream_add_all(AVFormatContext *s)
Definition: dvdvideodec.c:1357
int32_t
int32_t
Definition: audioconvert.c:56
timestamp.h
DVDVIDEO_SUBP_VIEWPORT_WIDESCREEN
@ DVDVIDEO_SUBP_VIEWPORT_WIDESCREEN
Definition: dvdvideodec.c:69
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_CHANNEL_LAYOUT_6POINT1
#define AV_CHANNEL_LAYOUT_6POINT1
Definition: channel_layout.h:404
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
DVDVideoPGCAudioStreamEntry::sample_rate
int sample_rate
Definition: dvdvideodec.c:91
dvdvideo_subp_stream_add_internal
static int dvdvideo_subp_stream_add_internal(AVFormatContext *s, uint32_t offset, subp_attr_t subp_attr, enum DVDVideoSubpictureViewport viewport)
Definition: dvdvideodec.c:1330
DVDVideoPGCAudioStreamEntry
Definition: dvdvideodec.c:87
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
DVDVideoPlaybackState::vob_file
dvd_file_t * vob_file
Definition: dvdvideodec.c:135
avstring.h
DVDVIDEO_SUBP_VIEWPORT_FULLSCREEN
@ DVDVIDEO_SUBP_VIEWPORT_FULLSCREEN
Definition: dvdvideodec.c:68
dvdvideo_menu_next_ps_block
static int dvdvideo_menu_next_ps_block(AVFormatContext *s, DVDVideoPlaybackState *state, uint8_t *buf, int buf_size, void(*flush_cb)(AVFormatContext *s))
Definition: dvdvideodec.c:392
AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_5POINT1
Definition: channel_layout.h:397
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
DVDVIDEO_TIME_BASE_Q
#define DVDVIDEO_TIME_BASE_Q
Definition: dvdvideodec.c:60
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:482
dvdvideo_nav_header
static const uint8_t dvdvideo_nav_header[4]
Definition: dvdvideodec.c:65
DVDVideoPlaybackState::pgc_elapsed
uint64_t pgc_elapsed
Definition: dvdvideodec.c:115
DVDVideoDemuxContext::opt_preindex
int opt_preindex
Definition: dvdvideodec.c:150
DVDVideoPGCAudioStreamEntry::lang_iso
const char * lang_iso
Definition: dvdvideodec.c:96
DVDVideoPlaybackState
Definition: dvdvideodec.c:107
DVDVideoDemuxContext::play_started
int play_started
Definition: dvdvideodec.c:169