/src/vlc/modules/demux/mkv/chapter_command_script.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (C) 2003-2024 VLC authors and VideoLAN |
2 | | // SPDX-License-Identifier: LGPL-2.1-or-later |
3 | | // |
4 | | // chapter_command_script.cpp : Matroska Script Codec for Matroska Chapter Codecs |
5 | | // Authors: Laurent Aimar <fenrir@via.ecp.fr> |
6 | | // Steve Lhomme <steve.lhomme@free.fr> |
7 | | |
8 | | |
9 | | #include "chapter_command_script.hpp" |
10 | | #include "virtual_segment.hpp" |
11 | | |
12 | | namespace mkv { |
13 | | |
14 | | //Matroska Script |
15 | | const std::string matroska_script_interpretor_c::CMD_MS_GOTO_AND_PLAY = "GotoAndPlay"; |
16 | | |
17 | | // see http://www.matroska.org/technical/specs/chapters/index.html#mscript |
18 | | // for a description of existing commands |
19 | | bool matroska_script_interpretor_c::Interpret( const binary * p_command, size_t i_size ) |
20 | 0 | { |
21 | 0 | bool b_result = false; |
22 | |
|
23 | 0 | std::string sz_command( reinterpret_cast<const char*> (p_command), i_size ); |
24 | |
|
25 | 0 | vlc_debug( l, "command : %s", sz_command.c_str() ); |
26 | |
|
27 | 0 | if ( sz_command.compare( 0, CMD_MS_GOTO_AND_PLAY.size(), CMD_MS_GOTO_AND_PLAY ) == 0 ) |
28 | 0 | { |
29 | 0 | size_t i,j; |
30 | | |
31 | | // find the ( |
32 | 0 | for ( i=CMD_MS_GOTO_AND_PLAY.size(); i<sz_command.size(); i++) |
33 | 0 | { |
34 | 0 | if ( sz_command[i] == '(' ) |
35 | 0 | { |
36 | 0 | i++; |
37 | 0 | break; |
38 | 0 | } |
39 | 0 | } |
40 | | // find the ) |
41 | 0 | for ( j=i; j<sz_command.size(); j++) |
42 | 0 | { |
43 | 0 | if ( sz_command[j] == ')' ) |
44 | 0 | { |
45 | 0 | i--; |
46 | 0 | break; |
47 | 0 | } |
48 | 0 | } |
49 | |
|
50 | 0 | std::string st = sz_command.substr( i+1, j-i-1 ); |
51 | 0 | chapter_uid i_chapter_uid = std::stoul( st ); |
52 | |
|
53 | 0 | virtual_segment_c *p_vsegment; |
54 | 0 | virtual_chapter_c *p_vchapter = vm.FindVChapter( i_chapter_uid, p_vsegment ); |
55 | |
|
56 | 0 | if ( p_vchapter == NULL ) |
57 | 0 | vlc_debug( l, "Chapter %" PRId64 " not found", i_chapter_uid); |
58 | 0 | else |
59 | 0 | { |
60 | 0 | if ( !p_vchapter->EnterAndLeave( vm.GetCurrentVSegment()->CurrentChapter(), false ) ) |
61 | 0 | vm.JumpTo( *p_vsegment, *p_vchapter ); |
62 | 0 | b_result = true; |
63 | 0 | } |
64 | 0 | } |
65 | |
|
66 | 0 | return b_result; |
67 | 0 | } |
68 | | |
69 | | } // namespace |