Coverage Report

Created: 2025-07-18 07:04

/src/vlc/modules/demux/mkv/events.hpp
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * events.hpp : matroska demuxer
3
 *****************************************************************************
4
 * Copyright (C) 2003-2004 VLC authors and VideoLAN
5
 *
6
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7
 *          Steve Lhomme <steve.lhomme@free.fr>
8
 *
9
 * This program is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU Lesser General Public License as published by
11
 * the Free Software Foundation; either version 2.1 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program; if not, write to the Free Software Foundation,
21
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
 *****************************************************************************/
23
24
#ifndef VLC_MKV_DEMUX_EVENTS_HPP
25
#define VLC_MKV_DEMUX_EVENTS_HPP
26
27
#include <vlc_common.h>
28
#include <vlc_threads.h>
29
#include <vlc_mouse.h>
30
31
#include <list>
32
#include <memory>
33
34
struct vlc_spu_highlight_t;
35
36
namespace mkv {
37
38
struct p_block;
39
40
class event_thread_t
41
{
42
public:
43
    event_thread_t(demux_t *);
44
    virtual ~event_thread_t();
45
46
    void SendData( mkv_track_t &, block_t * );
47
    void AbortThread();
48
    int SendEventNav( demux_query_e );
49
    void SetHighlight( vlc_spu_highlight_t & spu_hl );
50
51
    bool AddTrack( mkv_track_t & );
52
    void DelTrack( mkv_track_t & );
53
54
private:
55
    struct ESInfo {
56
        ESInfo( mkv_track_t & track_, event_thread_t& owner )
57
0
            : track( track_ )
58
0
            , owner( owner )
59
0
        {
60
0
            vlc_mouse_Init( &mouse_state );
61
0
        }
62
63
0
        bool operator==( const mkv_track_t & t ) const {
64
0
            return track.p_es == t.p_es;
65
0
        }
66
67
        mkv_track_t & track;
68
        event_thread_t& owner;
69
        vlc_mouse_t mouse_state;
70
    };
71
72
    struct EventInfo {
73
        enum {
74
            ESMouseEvent,
75
            ButtonDataEvent,
76
        } type;
77
78
        EventInfo( const vlc_mouse_t & state_old, const vlc_mouse_t & state_new )
79
0
            : type( ESMouseEvent )
80
0
            , mouse{ state_old, state_new }
81
0
        {
82
0
        }
83
84
        EventInfo( block_t * block )
85
0
            : type( ButtonDataEvent )
86
0
            , button_data( block, block_Release )
87
0
        {
88
0
        }
89
90
        union {
91
            struct {
92
                const vlc_mouse_t state_old;
93
                const vlc_mouse_t state_new;
94
            } mouse;
95
96
            struct {
97
                const NavivationKey key;
98
            } nav;
99
        };
100
101
        std::shared_ptr<block_t> button_data;
102
    };
103
104
    void EventThread();
105
    static void *EventThread(void *);
106
    void EnsureThreadLocked();
107
108
    static void EventMouse( vlc_mouse_t const* state, void* userdata );
109
110
    void HandleMouseEvent( EventInfo const& );
111
    void HandleButtonData( EventInfo const& );
112
113
    demux_t      *p_demux;
114
115
    bool         is_running;
116
    vlc_thread_t thread;
117
118
    vlc_mutex_t  lock;
119
    vlc_cond_t   wait;
120
    bool         b_abort = false;
121
122
    typedef std::list<ESInfo> es_list_t;
123
    es_list_t es_list;               //protected by "lock"
124
125
    typedef std::list<EventInfo> pending_events_t;
126
    pending_events_t pending_events; // protected by "lock"
127
128
    void QueueEvent(const EventInfo & e)
129
0
    {
130
0
        vlc_mutex_locker lock_guard( &lock );
131
132
0
        EnsureThreadLocked();
133
134
0
        pending_events.push_back( e );
135
0
        vlc_cond_signal( &wait );
136
0
    }
137
138
    bool HandleKeyEvent( NavivationKey key );
139
    void HandleMousePressed( unsigned x, unsigned y );
140
    void HandleButtonData( block_t * );
141
};
142
} // namespace
143
144
#endif