summaryrefslogtreecommitdiffstats
path: root/Src/VodHandler.h
blob: 030c08e398aacb8fe8f5820cf1711a621ba00d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Video On Demand Samples
 *
 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You may also obtain this software under a propriety license from Microchip.
 * Please contact Microchip for further information.
 *
 */

/*----------------------------------------------------------*/
/*! \file
 *  \brief  This file contains the CVodHandler class.
 */
/*----------------------------------------------------------*/
#ifndef VODHANDLER_H
#define VODHANDLER_H

#include "Multiplexer.h"
#include "Source.h"
#include "Thread.h"
#include "ConnectionInfo.h"
#include "MostIpc.h"
#include "MacAddr.h"
#include "MsgAddr.h"
#include "MostMsg.h"

typedef enum
{
    SelectFileType_Video = 0,
    SelectFileType_Audio = 1,
    SelectFileType_Radio = 2,
    SelectFileType_Navigation = 3,
    SelectFileType_Cluster = 4
} SelectFileType_t;

/*----------------------------------------------------------*/
/*! \brief Structure holding the file name and the pointer to the CSourceFile object.
 */
/*----------------------------------------------------------*/
typedef struct
{
    char fileName[128];
    CSource *sourceFile;
} BroadcastEntry_t;

/*!
 * \brief  Applications main entry point and event handler, as it implements callbacks from CNetworkListener.
 *         It controls the Network via the CNetwork class.
 *         Isochronous TX connections will be automatically connected to the CMultiplexer class.
 */
class CVodHandler : public CThread
{
private:
    CSafeVector<BroadcastEntry_t *> broadcastFiles;
    CSafeVector<CMultiplexer *> allMultiplexer;
    CSafeVector<char *> ignoreCdevPatterns;
    bool networkManagerFound;
    char networkManagerIP[100];
    bool valuesCleared;
    bool statisticIsEnabled;
    char searchPath[64];
    CConnectionInfoContainer *infoContainer;
    pthread_mutex_t infoContainerMutex;
    
    CMostIpc *mostIpcVod;
    CMsgFilter *vodSelectFile_Set;
    CMsgFilter *vodPlayMode_Set;
    CMsgFilter *vodTimePostion_Set;
    CMsgFilter *vodRepetition_Set;
    CMsgFilter *vodServerVersion_Get;
    CMsgFilter *vodMediaPid_Get;
    CMsgFilter *vodFileList_Get;
    CMsgFilter *vodIndependStream_SetGet;
    CMsgFilter *vodFakeMode_Set;

    CMostIpc *mostIpcNm;
    CMsgFilter *nmServerVersion_Status;
    CMsgFilter *nmConnectionList_Status;

    CVodHandler();
    virtual ~CVodHandler();
    static const char *GetSubPath( SelectFileType_t fileType );
    static bool ExistsFile( const char *pFileName );
    CMultiplexer *GetMultiplexer( const char* deviceName );
    void RegisterBroadcastFiles( SelectFileType_t fileType );
    CMultiplexer *GetMultiplexer( const uint8_t *mac );
    void NM_SendServerVersionGetRequest( const char *ip );

    static void OnVodSelectFile_Set( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodPlayMode_Set( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodTimePosition_Set( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodRepetition_Set( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodServerVersion_Get( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodMediaPid_Get( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodFileList_Get( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnVodIndependentStream_SetGet( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnFakeMode_Set( CMsgAddr *pAddr, CMostMsg *pMsg );

    static void OnNmServerVersion_Status( CMsgAddr *pAddr, CMostMsg *pMsg );
    static void OnNmConnectionList_Status( CMsgAddr *pAddr, CMostMsg *pMsg );
public:

    static CVodHandler *GetInstance();

    static void DestroyInstance();

    void ConnectToNetworkManager();
    void GetConnectionListFromNetworkManager();
    bool CreateMacIndependentStream(uint8_t cdevIndex, uint8_t streamIndex, uint8_t *outMac);
    void CreateSampleStreams( uint8_t amount );

    void SetSearchPath( const char *pSearchPath );
    void SetCdevIgnorePattern( const char *pIgnorePattern );

    /*----------------------------------------------------------*/
    /*! \brief Streams a transport stream file via the specified multiplexer.
     *  \param mac - The MAC address of the sink.
     *  \param fileName - The full path to the transport stream file to play.
     *  \return true, if the stream is acceptable and the multiplexer exists.
     *          false, the stream can not be read or there is no multiplexer assigned with this connection.
     *  \note Make sure, the given sinkIndex points to a TX connection with a valid CMultiplexer object assigned.
     */
    /*----------------------------------------------------------*/
    bool StreamFile( const uint8_t *mac, SelectFileType_t fileType, const char *fileName );

    /*----------------------------------------------------------*/
    /*! \brief Set the pause state for a stream.
     *  \param mac - The MAC address of the sink.
     *  \param isPaused - If set to true, the video file will be paused.
     *  \return true, if the stream pause state could be toggled. false, otherwise.
     *  \note Make sure, the given sinkIndex points to a TX connection with a valid CMultiplexer object assigned.
     *  \note Make sure, that there is a file currently playing. Started with the StreamFile method.
     */
    /*----------------------------------------------------------*/
    bool SetPause( const uint8_t *mac, bool isPaused );

    /*----------------------------------------------------------*/
    /*! \brief Set the repetition state for a stream.
     *  \param mac - The MAC address of the sink.
     *  \param isRepeated - If set to true, the video file will be repeated.
     *  \return true, if the stream repetition state could be toggled. false, otherwise.
     *  \note Make sure, that there is a file currently playing. Started with the StreamFile method.
     */
    /*----------------------------------------------------------*/
    bool SetRepetition( const uint8_t *mac, bool isRepeated );

    /*----------------------------------------------------------*/
    /*! \brief Sets the time position of the given stream.
     *  \param mac - The MAC address of the sink.
     *  \return true, if the stream's time position could be adjusted to given value. false, otherwise.
     *  \note Make sure, that there is a file currently playing. Started with the StreamFile method.
     */
    /*----------------------------------------------------------*/
    bool SetTimePos( const uint8_t *mac, uint16_t timePosPerMile );

    /*----------------------------------------------------------*/
    /*! \brief Stops the playback of the given stream.
     *  \param mac - The MAC address of the sink.
     *  \return true, if the stream was stopped. false, otherwise.
     *  \note Make sure, that there is a file currently playing. Started with the StreamFile method.
     */
    /*----------------------------------------------------------*/
    bool StopStream( const uint8_t *mac );

    /*----------------------------------------------------------*/
    /*! \brief Toggle on / off the printing of Multiplexer Statistics
     */
    /*----------------------------------------------------------*/
    void ToggleStatisticsPrint();

    /*----------------------------------------------------------*/
    /*! \brief Thread method performing the cyclic Multiplexer Statistic prints.
     *  \warning Never call this method directly. Use ToggleStatisticsPrint instead!
     */
    /*----------------------------------------------------------*/
    void Run();
};

#endif //VODHANDLER_H