| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2007-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_playback_impl.h $ |
|---|
| 39 | * $brcm_Revision: 39 $ |
|---|
| 40 | * $brcm_Date: 12/6/11 8:38a $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /nexus/modules/playback/src/nexus_playback_impl.h $ |
|---|
| 47 | * |
|---|
| 48 | * 39 12/6/11 8:38a erickson |
|---|
| 49 | * SW7405-5559: remove uninitialized p->record and replace with p- |
|---|
| 50 | * >params.timeshifting test |
|---|
| 51 | * |
|---|
| 52 | * 38 9/22/11 4:43p erickson |
|---|
| 53 | * SW7420-1965: add simple decoder support to nexus playback module |
|---|
| 54 | * |
|---|
| 55 | * 37 9/7/11 11:41a erickson |
|---|
| 56 | * SW7405-5059: fail stc trick if any decoder not in TSM mode |
|---|
| 57 | * |
|---|
| 58 | * 36 3/28/11 3:45p vsilyaev |
|---|
| 59 | * SW7335-1214: Added NEXUS_CallbackHandler framework |
|---|
| 60 | * |
|---|
| 61 | * 35 3/23/11 3:00p vsilyaev |
|---|
| 62 | * SW7422-14: Added facility to associate stream id(pid) with a chunk of |
|---|
| 63 | * payload |
|---|
| 64 | * |
|---|
| 65 | * 34 2/24/11 1:36p vsilyaev |
|---|
| 66 | * SWDTV-5485: Differentiates ES and ES->PES types |
|---|
| 67 | * |
|---|
| 68 | * 33 10/22/10 11:46a vsilyaev |
|---|
| 69 | * SW35230-1600: When decrypting payload clear file buffer on transitions. |
|---|
| 70 | * |
|---|
| 71 | * 32 9/28/10 1:57p erickson |
|---|
| 72 | * SWDEPRECATED-1003: pass force source frame rate from media framework to |
|---|
| 73 | * VideoDecoder |
|---|
| 74 | * |
|---|
| 75 | * 31 6/29/10 3:20p erickson |
|---|
| 76 | * SW7405-4367: playback should flush when transitioning decoder skip |
|---|
| 77 | * modes. also added NEXUS_PlaybackTrickModeSettings.avoidFlush option to |
|---|
| 78 | * disable this behavior. |
|---|
| 79 | * |
|---|
| 80 | * 30 4/2/10 2:37p erickson |
|---|
| 81 | * SW7405-3833: nexus_file_pvr.h is now part of the public API |
|---|
| 82 | * |
|---|
| 83 | * 29 3/11/10 5:26p vsilyaev |
|---|
| 84 | * SW3556-913: Always use header file to declare external functions |
|---|
| 85 | * |
|---|
| 86 | * 28 3/5/10 7:13p jtna |
|---|
| 87 | * SW3556-913: support for ErrorHandlingMode_eAbort |
|---|
| 88 | * |
|---|
| 89 | * 27 2/23/10 4:53p erickson |
|---|
| 90 | * SW7400-2684: add state variable so we only fire beginningOfStreamAction |
|---|
| 91 | * or endOfStreamAction once when paused |
|---|
| 92 | * |
|---|
| 93 | * 26 12/17/09 5:52p vsilyaev |
|---|
| 94 | * SW3548-2677: Added configuration that allows user to choose what |
|---|
| 95 | * context should be used for synchronous I/O |
|---|
| 96 | * |
|---|
| 97 | * 25 7/31/09 4:25p erickson |
|---|
| 98 | * PR57235: rename Settop API names, remove unused code |
|---|
| 99 | * |
|---|
| 100 | * 24 7/29/09 2:05p mward |
|---|
| 101 | * PR57192: Reduce stack use in b_play_mpeg2ts_probe_index. |
|---|
| 102 | * |
|---|
| 103 | * 23 7/8/09 3:25p vsilyaev |
|---|
| 104 | * PR 55989: Used size of the video decoder CDB to control size of the |
|---|
| 105 | * data chunk |
|---|
| 106 | * |
|---|
| 107 | * 22 7/8/09 11:59a vsilyaev |
|---|
| 108 | * PR 55989: Added support for OTF trickmodes |
|---|
| 109 | * |
|---|
| 110 | * 21 6/4/09 5:03p erickson |
|---|
| 111 | * PR54129: remove SEEK_CUR which results in loss of packet alignment when |
|---|
| 112 | * a file fifo is trimmed. consolidate logic in |
|---|
| 113 | * NEXUS_Playback_P_EndOfDataFile. |
|---|
| 114 | * |
|---|
| 115 | * 20 3/5/09 5:46p vsilyaev |
|---|
| 116 | * PR 52579: Updated circular FIFO/timeshifting code |
|---|
| 117 | * |
|---|
| 118 | * 19 2/26/09 9:03a erickson |
|---|
| 119 | * PR52099: block all TrickState calls to AudioDecoder and VideoDecoder if |
|---|
| 120 | * NEXUS_PlaybackHostTrickMode_eNormal is set. also removed some old, |
|---|
| 121 | * unused code. |
|---|
| 122 | * |
|---|
| 123 | * 17 1/27/09 4:04p erickson |
|---|
| 124 | * PR51377: NEXUS_Playback_Start or NEXUS_Playback_OpenPidChannel should |
|---|
| 125 | * reset VideoDecoder's trick state |
|---|
| 126 | * |
|---|
| 127 | * 16 1/26/09 11:38a vsilyaev |
|---|
| 128 | * PR 51579: Added ES to PES packetization and support for capturing of |
|---|
| 129 | * streams produced by the playback module |
|---|
| 130 | * |
|---|
| 131 | * 15 1/12/09 5:45p vsilyaev |
|---|
| 132 | * PR 50763: Improved seek to position 0 after rewind reached begining of |
|---|
| 133 | * the file |
|---|
| 134 | * |
|---|
| 135 | * 14 12/19/08 5:59p vsilyaev |
|---|
| 136 | * PR 50214: Added callbacks and counters for parsing index files |
|---|
| 137 | * |
|---|
| 138 | * 13 12/10/08 4:42p erickson |
|---|
| 139 | * PR49930: add internal accurate seek algorithm for driving audio through |
|---|
| 140 | * the transition |
|---|
| 141 | * |
|---|
| 142 | * 12 12/10/08 11:05a erickson |
|---|
| 143 | * PR49930: added NEXUS_Playback_AccurateSeekInProcess test api, added |
|---|
| 144 | * required flush before calling NEXUS_VideoDecoder_SetStartPts |
|---|
| 145 | * |
|---|
| 146 | * 11 12/8/08 11:20a erickson |
|---|
| 147 | * PR49930: implement NEXUS_PlaybackSettings.accurateSeek |
|---|
| 148 | * |
|---|
| 149 | * 10 10/21/08 10:06a vsilyaev |
|---|
| 150 | * PR 47225: Streamlined logic to detect EndOfStream condition |
|---|
| 151 | * |
|---|
| 152 | * 9 10/14/08 3:36p erickson |
|---|
| 153 | * PR47407: reapply audio decoder trick mode settings when pid channel is |
|---|
| 154 | * opened or set |
|---|
| 155 | * |
|---|
| 156 | * 8 10/6/08 11:48a gmohile |
|---|
| 157 | * PR 47608 : Invalidate STC channel during flush |
|---|
| 158 | * |
|---|
| 159 | * 7 7/24/08 4:34p erickson |
|---|
| 160 | * PR45124: allow duplicate calls to NEXUS_Playback_OpenPidChannel and |
|---|
| 161 | * ref_cnt internally |
|---|
| 162 | * |
|---|
| 163 | * 6 7/3/08 1:07p vsilyaev |
|---|
| 164 | * PR 44381: Added code to limi nestendess of recursive calls |
|---|
| 165 | * |
|---|
| 166 | * 5 6/13/08 5:37p katrep |
|---|
| 167 | * PR43437: Add logic the detect the eof if the CDB is not getting |
|---|
| 168 | * consumed by the decoders. |
|---|
| 169 | * |
|---|
| 170 | * 4 6/12/08 3:02p erickson |
|---|
| 171 | * PR43606: rename NEXUS_PlaybackStreamSettings to |
|---|
| 172 | * NEXUS_PlaybackStartSettings |
|---|
| 173 | * |
|---|
| 174 | * 3 5/5/08 5:42p vsilyaev |
|---|
| 175 | * PR 42355: Fixed transition from trickmode to frame advance/reverse |
|---|
| 176 | * |
|---|
| 177 | * 2 3/8/08 7:45a erickson |
|---|
| 178 | * PR40103: convert to NEXUS_TaskCallback |
|---|
| 179 | * |
|---|
| 180 | * 1 1/18/08 2:36p jgarrett |
|---|
| 181 | * PR 38808: Merging to main branch |
|---|
| 182 | * |
|---|
| 183 | * Nexus_Devel/9 1/8/08 2:23p vsilyaev |
|---|
| 184 | * PR 35824: Fixed resync on transition between modes |
|---|
| 185 | * |
|---|
| 186 | * Nexus_Devel/8 1/7/08 5:09p erickson |
|---|
| 187 | * PR35824: add new continuous record support |
|---|
| 188 | * |
|---|
| 189 | * Nexus_Devel/7 12/21/07 5:55p vsilyaev |
|---|
| 190 | * PR 38073: Fixed fa -> fb -> play transitions |
|---|
| 191 | * |
|---|
| 192 | * Nexus_Devel/6 12/20/07 3:41p vsilyaev |
|---|
| 193 | * PR 38073: Improving use of bmedia_player |
|---|
| 194 | * |
|---|
| 195 | * Nexus_Devel/5 12/20/07 10:29a vsilyaev |
|---|
| 196 | * PR 38073: Updated to work with new bmedia_player |
|---|
| 197 | * |
|---|
| 198 | * Nexus_Devel/PR38073/3 12/19/07 5:01p vsilyaev |
|---|
| 199 | * PR 38073: Moved time tracking code for host paced mode into the |
|---|
| 200 | * bmedia_player |
|---|
| 201 | * |
|---|
| 202 | * Nexus_Devel/PR38073/2 12/18/07 6:45p vsilyaev |
|---|
| 203 | * PR 38073: Added handling of no-index streams |
|---|
| 204 | * |
|---|
| 205 | * Nexus_Devel/PR38073/1 12/18/07 4:57p vsilyaev |
|---|
| 206 | * PR 38073: Updated playback module to work exclusively with media player |
|---|
| 207 | * |
|---|
| 208 | * Nexus_Devel/4 10/30/07 5:05p vsilyaev |
|---|
| 209 | * PR 36404: Added audio tracking for slow motion modes |
|---|
| 210 | * |
|---|
| 211 | * Nexus_Devel/3 10/17/07 1:05p vsilyaev |
|---|
| 212 | * PR 35824: Added playpump_trick |
|---|
| 213 | * |
|---|
| 214 | * Nexus_Devel/2 10/16/07 4:59p vsilyaev |
|---|
| 215 | * PR 35824: Rearranged code |
|---|
| 216 | * |
|---|
| 217 | * Nexus_Devel/1 10/16/07 12:56p vsilyaev |
|---|
| 218 | * PR 35824: Splitting playback into managable piexies |
|---|
| 219 | * |
|---|
| 220 | * Nexus_Devel/5 10/15/07 2:55p vsilyaev |
|---|
| 221 | * PR 35824: Added synchronization thunk layer |
|---|
| 222 | * |
|---|
| 223 | * Nexus_Devel/4 10/12/07 5:44p vsilyaev |
|---|
| 224 | * PR 35824: Added more implementation for playback module |
|---|
| 225 | * |
|---|
| 226 | * Nexus_Devel/2 10/10/07 5:33p vsilyaev |
|---|
| 227 | * PR 35824: Added association with the audio/video decoders |
|---|
| 228 | * |
|---|
| 229 | * Nexus_Devel/1 10/10/07 4:54p vsilyaev |
|---|
| 230 | * PR 35824: Playback module |
|---|
| 231 | * |
|---|
| 232 | **************************************************************************/ |
|---|
| 233 | #ifndef NEXUS_PLAYBACK_IMPL_H__ |
|---|
| 234 | #define NEXUS_PLAYBACK_IMPL_H__ |
|---|
| 235 | |
|---|
| 236 | #include "nexus_playback.h" |
|---|
| 237 | #include "blst_slist.h" |
|---|
| 238 | #include "bfile_io.h" |
|---|
| 239 | #include "nexus_file_pvr.h" |
|---|
| 240 | #include "bmedia_player.h" |
|---|
| 241 | #include "bmedia_util.h" |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | /* #define B_PLAYBACK_CAPTURE 1 */ |
|---|
| 245 | |
|---|
| 246 | #if B_PLAYBACK_CAPTURE |
|---|
| 247 | #include <stdio.h> |
|---|
| 248 | void b_play_capture_open(NEXUS_PlaybackHandle p); |
|---|
| 249 | void b_play_capture_close(NEXUS_PlaybackHandle p); |
|---|
| 250 | void b_play_capture_write(NEXUS_PlaybackHandle p, const void *buf, size_t len); |
|---|
| 251 | #else |
|---|
| 252 | #define b_play_capture_write(p, buf, len) |
|---|
| 253 | #define b_play_capture_open(p) |
|---|
| 254 | #define b_play_capture_close(p) |
|---|
| 255 | #endif |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | #ifdef __cplusplus |
|---|
| 259 | extern "C" { |
|---|
| 260 | #endif |
|---|
| 261 | |
|---|
| 262 | /* |
|---|
| 263 | * all requests in playback are called synchronously with data flow, so for example |
|---|
| 264 | * we could jump to any position immediatly, without waiting for frame to be decoded |
|---|
| 265 | * while in slowmotion mode. However not desctructive operations, such as pause, |
|---|
| 266 | * frameadvance, play, should be performed asynchronously. In order to allow that |
|---|
| 267 | * we should store command and handle it when it's possible. With such scheme some |
|---|
| 268 | * commands, like frameadvace, with cumulative effect require us to accumulate commands. |
|---|
| 269 | * This queue is cleared by any desctructive command, such as jump */ |
|---|
| 270 | |
|---|
| 271 | enum b_playback_state { |
|---|
| 272 | /* because we have another state bplayback_state, start this one from 100, so we could at least separate between those two */ |
|---|
| 273 | eTransition=100, /* set when we are about to transition our state, usually it's not seen by neither event handlers */ |
|---|
| 274 | eWaitingPlayback, /* set when we are waiting for playback buffer */ |
|---|
| 275 | eWaitingIo, /* set when I/O is in progress and we are waiting completeion */ |
|---|
| 276 | eWaitingRecord, /* set when we are waiting for record to notify us about data written to the file */ |
|---|
| 277 | eCancelIo, /* state when API request data pump to cancel I/O */ |
|---|
| 278 | eIoCanceled, /* acknowledgement set, if I/O was canceled */ |
|---|
| 279 | eSleeping, |
|---|
| 280 | eAborted, |
|---|
| 281 | eStopping, |
|---|
| 282 | eTimer, /* waiting for callback from b_timer api */ |
|---|
| 283 | eStopped |
|---|
| 284 | }; |
|---|
| 285 | |
|---|
| 286 | /* this type is used to set where control activation is coming from */ |
|---|
| 287 | enum b_control_origin { |
|---|
| 288 | eControlFrame, /* control is called from the frame feed routine */ |
|---|
| 289 | eControlData, /* control is called from the internal data feeding loop */ |
|---|
| 290 | eControlDataIO /* control is called from the I/O request handler */ |
|---|
| 291 | }; |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | typedef struct NEXUS_Playback_P_PidChannel { |
|---|
| 295 | BLST_S_ENTRY(NEXUS_Playback_P_PidChannel) link; |
|---|
| 296 | NEXUS_PidChannelHandle pidChn; |
|---|
| 297 | uint16_t pid; |
|---|
| 298 | NEXUS_PlaybackPidChannelSettings cfg; |
|---|
| 299 | int ref_cnt; |
|---|
| 300 | } NEXUS_Playback_P_PidChannel; |
|---|
| 301 | |
|---|
| 302 | BDBG_OBJECT_ID_DECLARE(NEXUS_Playback); |
|---|
| 303 | |
|---|
| 304 | typedef enum b_trick_state { |
|---|
| 305 | b_trick_state_normal, /* Host sends unmodified stream to decoder */ |
|---|
| 306 | b_trick_state_host_trick_mode, /* Host manipulates the stream before sending to decoder for vsync decode */ |
|---|
| 307 | b_trick_state_brcm_trick_mode, /* Host manipulates the stream, including embedded BTP's, before sending to decoder for vsync decode */ |
|---|
| 308 | b_trick_state_host_paced, /* Host manipulates the stream and the PTS's before sending to decoder for TSM decode */ |
|---|
| 309 | b_trick_state_display_queue_trick_mode /* Host sends beginning of GOP for decode and post-decode reordering */ |
|---|
| 310 | } b_trick_state; |
|---|
| 311 | |
|---|
| 312 | typedef struct b_trick_settings { |
|---|
| 313 | b_trick_state state; |
|---|
| 314 | unsigned decode_rate; /* based on NEXUS_NORMAL_PLAY_SPEED */ |
|---|
| 315 | NEXUS_VideoDecoderDecodeMode decode_mode; /* Special mode the decoder. Often used to skip content. */ |
|---|
| 316 | NEXUS_VideoDecoderReorderingMode reordering_mode; /* decoder receives out-of-order fragments of the stream */ |
|---|
| 317 | bool fragmented; /* decoder receives fragments of the stream */ |
|---|
| 318 | bool forward; /* if false, reverse the display of fields */ |
|---|
| 319 | bool stc_trick; |
|---|
| 320 | bool audio_only_pause; |
|---|
| 321 | bool set_decoders; /* if true, Playback can set decoder trick state. if false, don't set it. */ |
|---|
| 322 | bool avoid_flush; |
|---|
| 323 | unsigned force_source_frame_rate; |
|---|
| 324 | } b_trick_settings; |
|---|
| 325 | |
|---|
| 326 | struct NEXUS_Playback { |
|---|
| 327 | BDBG_OBJECT(NEXUS_Playback) |
|---|
| 328 | NEXUS_FilePlayHandle file; |
|---|
| 329 | bmedia_player_t media_player; /* media player is used to play various container formats */ |
|---|
| 330 | BKNI_EventHandle ack_event; /* feedback to public api context that processing has been stopped */ |
|---|
| 331 | BKNI_EventHandle playpump_event; /* event from the playpump */ |
|---|
| 332 | NEXUS_EventCallbackHandle playpump_event_callback; /* callback called in responce of playpump_event */ |
|---|
| 333 | NEXUS_ThreadHandle playpump_thread; /* thread that is used to handle callbacks from playpump */ |
|---|
| 334 | BKNI_EventHandle playpump_thread_event; /* event that is used to wakeup playpump thread */ |
|---|
| 335 | BLST_S_HEAD(NEXUS_Playback_P_PidChannels, NEXUS_Playback_P_PidChannel) pid_list; |
|---|
| 336 | NEXUS_TaskCallbackHandle errorCallback, endOfStreamCallback, beginningOfStreamCallback, parsingErrorCallback; |
|---|
| 337 | NEXUS_PlaybackIndexFileIo index_file_mode; /* control what context is used for index file I/O */ |
|---|
| 338 | NEXUS_CallbackHandler dataCallbackHandler; |
|---|
| 339 | NEXUS_CallbackHandler videoDecoderFirstPts; |
|---|
| 340 | NEXUS_CallbackHandler videoDecoderFirstPtsPassed; |
|---|
| 341 | bool thread_terminate; /* set to true when playpump_thread should exit */ |
|---|
| 342 | |
|---|
| 343 | NEXUS_PlaybackSettings params; |
|---|
| 344 | NEXUS_TransportType actualTransportType; /* format of data sent to the playpump, might be different from params.playpumpSettings.transportType if player convers stream format */ |
|---|
| 345 | void *buf_limit; /* The last start point if can use in the playback buffer with O_DIRECT */ |
|---|
| 346 | |
|---|
| 347 | /* the following structure is "state" which is zeroed out on bplayback_start. */ |
|---|
| 348 | struct { |
|---|
| 349 | bool drain_mode; /* set to true if we are in a drain mode, waiting for the decoder FIFO to go empty */ |
|---|
| 350 | NEXUS_PlaybackState mode; /* external state */ |
|---|
| 351 | bool loopedDuringPause; /* only fire beginningOfStreamAction or endOfStreamAction once when paused */ |
|---|
| 352 | |
|---|
| 353 | enum b_playback_state state; /* current state of the data pump */ |
|---|
| 354 | int direction; |
|---|
| 355 | int index_entrysize; /* the sizeof each index entry. depends on BNAV_Version. */ |
|---|
| 356 | |
|---|
| 357 | void *buf; /* buffer which points to the playback buffer */ |
|---|
| 358 | size_t read_size; /* size of the last I/O transaction, this is size passed into read */ |
|---|
| 359 | |
|---|
| 360 | /* The following handle detection of end-of-decode without losing data in the fifos */ |
|---|
| 361 | uint32_t fifoMarker; /* some marker which shows activity when decoding. currently using video PTS */ |
|---|
| 362 | NEXUS_Time fifoLast; /* last time when fifoMarker has changed */ |
|---|
| 363 | int fifoMarkerCounter; /* used for frame advance only */ |
|---|
| 364 | |
|---|
| 365 | void (*data_source) (NEXUS_PlaybackHandle p); /* function called when data may become avaliable in the playback buffer */ |
|---|
| 366 | NEXUS_PlaybackTrickModeSettings trickmode_params; /* parameters used for trick mode (fastforward or rewind) */ |
|---|
| 367 | bool reset; /* it's set to false, when control enters into the API function, |
|---|
| 368 | code might want set it to true what would |
|---|
| 369 | force decoder and playback will be flushed before continuing normal execution */ |
|---|
| 370 | bool start_paused; /* playback in started, but in paused state, wait for bplayback_play function to resume playback */ |
|---|
| 371 | ssize_t io_size; /* this is used to revive canceled I/O, it keeps number of bytes what I/O has returned */ |
|---|
| 372 | NEXUS_TimerHandle timer; /* currently active timer or NULL */ |
|---|
| 373 | struct { |
|---|
| 374 | /* this state is used to manager virtual I/O, so all offsets in the |
|---|
| 375 | file are 4K aligned */ |
|---|
| 376 | size_t file_behind; /* number of bytes which we had to seek backwards in the file |
|---|
| 377 | in order to read the file in 4K pages */ |
|---|
| 378 | size_t junk_data; /* amount of data being skipped in the playback buffer. This |
|---|
| 379 | is equal to file_behind + whatever is needed to page-align |
|---|
| 380 | the playback buffer memory */ |
|---|
| 381 | size_t next_data; /* number of bytes which were read in addition into the playback buffer, |
|---|
| 382 | which will become the next file_behind value unless we |
|---|
| 383 | have to seek to a new location. */ |
|---|
| 384 | off_t last_file_offset; /* allow playback to use SEEK_SET to recover from a bad read. if playback was to use SEEK_CUR, |
|---|
| 385 | it could lose alignment due to file fifo trim. */ |
|---|
| 386 | } io; |
|---|
| 387 | struct { |
|---|
| 388 | unsigned cur; /* current index into the packet buffer */ |
|---|
| 389 | unsigned size; /* last valid byte in the packet buffer */ |
|---|
| 390 | const uint8_t *buf; |
|---|
| 391 | } packet; /* structure to handle injected packets */ |
|---|
| 392 | struct { |
|---|
| 393 | unsigned cur; /* current byte what we have read */ |
|---|
| 394 | unsigned size; /* number of bytes what we have to read */ |
|---|
| 395 | off_t offset; /* offset in a file for the frame payload */ |
|---|
| 396 | } frame; |
|---|
| 397 | bool encrypted; /* true for encrypted playback on RAVE platforms */ |
|---|
| 398 | bool decoder_flushed; /* used to indicate that decoder/playback buffers were flushed, it's function to remove back-to-back flushes and indicate that media player shall be restarted */ |
|---|
| 399 | struct { |
|---|
| 400 | bool segmented; |
|---|
| 401 | uint8_t *last_segment_hdr; /* last address where the sequnece header could start */ |
|---|
| 402 | bmedia_player_entry entry; |
|---|
| 403 | bmedia_time_scale time_scale; |
|---|
| 404 | NEXUS_TimerHandle pts_timer; /* periodic 10sec timer go get current PTS and update index_offset */ |
|---|
| 405 | batom_factory_t factory; |
|---|
| 406 | bfile_buffer_t buffer; |
|---|
| 407 | void *buf; /* memory allocated for the buffer */ |
|---|
| 408 | batom_cursor cursor; |
|---|
| 409 | struct { /* status for b_lock'ed async I/O */ |
|---|
| 410 | void (*read_cont)(void *cont, ssize_t size); |
|---|
| 411 | void *cntx; |
|---|
| 412 | } async_read; |
|---|
| 413 | unsigned nest_count; |
|---|
| 414 | NEXUS_TimerHandle nest_timer; |
|---|
| 415 | uint8_t probe_buf[4096]; |
|---|
| 416 | } media; |
|---|
| 417 | enum {NEXUS_Playback_P_FrameAdvance_Invalid, NEXUS_Playback_P_FrameAdvance_Forward, NEXUS_Playback_P_FrameAdvance_Reverse} frame_advance; /* this state variable keeeps track of compatible frameadvance mode (e.g. play is compatible with frameforward and 1xrewind compatible with framereverse, and 2xfastforward not compatible with either */ |
|---|
| 418 | |
|---|
| 419 | bool inAccurateSeek; |
|---|
| 420 | bool validPts; |
|---|
| 421 | |
|---|
| 422 | bmedia_player_pos abortPosition; /* last playback position before abort */ |
|---|
| 423 | unsigned index_error_cnt; |
|---|
| 424 | unsigned data_error_cnt; |
|---|
| 425 | } state; |
|---|
| 426 | #if B_PLAYBACK_CAPTURE |
|---|
| 427 | struct { |
|---|
| 428 | bool has_data; |
|---|
| 429 | unsigned no; |
|---|
| 430 | FILE *fout; |
|---|
| 431 | } capture; |
|---|
| 432 | #endif |
|---|
| 433 | struct { |
|---|
| 434 | b_trick_settings settings; |
|---|
| 435 | NEXUS_TimerHandle rap_monitor_timer; |
|---|
| 436 | } trick; |
|---|
| 437 | NEXUS_ThreadSettings playpump_thread_settings; |
|---|
| 438 | }; |
|---|
| 439 | |
|---|
| 440 | #define B_IO_BLOCK_SIZE BIO_BLOCK_SIZE |
|---|
| 441 | #define B_IO_BLOCK_LIMIT (4*B_IO_BLOCK_SIZE) |
|---|
| 442 | #define B_IO_ALIGN_TRUNC(n) ((n)&(~(B_IO_BLOCK_SIZE-1))) |
|---|
| 443 | #define B_IO_ALIGN_ROUND(n) (((n)+B_IO_BLOCK_SIZE-1)&(~(B_IO_BLOCK_SIZE-1))) |
|---|
| 444 | #define B_IO_ALIGN_REST(n) (((unsigned)(n)) & (B_IO_BLOCK_SIZE-1)) |
|---|
| 445 | |
|---|
| 446 | #define B_MEDIA_ATOM_MAGIC (-2) |
|---|
| 447 | #define B_MEDIA_NEST_MAGIC (-3) |
|---|
| 448 | |
|---|
| 449 | /* related to frame time, but doesn't need to be exact */ |
|---|
| 450 | #define B_FRAME_DISPLAY_TIME 30 |
|---|
| 451 | |
|---|
| 452 | #define B_ONE(s,val,str,next) (((s)==(val)?(str):(next))) |
|---|
| 453 | #define B_LAST(s,val,str) (((s)==(val)?(str):("#Invalid#"))) |
|---|
| 454 | #define B_BOOL_STR(v,tr,fl) ((v)?(tr):(fl)) |
|---|
| 455 | |
|---|
| 456 | #define B_TRICK_STATE_STR(s) B_ONE(s, b_trick_state_normal,"normal",B_ONE(s, b_trick_state_host_paced,"host_paced", B_ONE(s, b_trick_state_host_trick_mode,"host",B_ONE(s, b_trick_state_display_queue_trick_mode,"dqt",B_LAST(s, b_trick_state_brcm_trick_mode, "BRCM"))))) |
|---|
| 457 | #define B_FORWARD_STR(s) B_BOOL_STR(s,"forward","reverse") |
|---|
| 458 | #define B_DECODE_MODE_STR(s) B_ONE(s, NEXUS_VideoDecoderDecodeMode_eAll, "all",B_ONE(s, NEXUS_VideoDecoderDecodeMode_eI, "I", B_LAST(s, NEXUS_VideoDecoderDecodeMode_eIP, "IP"))) |
|---|
| 459 | |
|---|
| 460 | void b_play_check_buffer(NEXUS_PlaybackHandle p); |
|---|
| 461 | void b_play_read_callback(void *context); |
|---|
| 462 | |
|---|
| 463 | /* index play */ |
|---|
| 464 | void b_play_next_frame(NEXUS_PlaybackHandle p); |
|---|
| 465 | void b_play_send_packet(NEXUS_PlaybackHandle p); |
|---|
| 466 | void b_play_frame_data(void *playback_, ssize_t size); |
|---|
| 467 | NEXUS_Error b_play_start_drain(NEXUS_PlaybackHandle p); |
|---|
| 468 | void b_play_send_frame(NEXUS_PlaybackHandle p); |
|---|
| 469 | void b_play_timer(void *); |
|---|
| 470 | |
|---|
| 471 | bool b_play_control(NEXUS_PlaybackHandle playback, enum b_control_origin origin); |
|---|
| 472 | void b_play_update_location(NEXUS_PlaybackHandle p); |
|---|
| 473 | |
|---|
| 474 | NEXUS_Error b_play_media_handle_loop_condition(NEXUS_PlaybackHandle p, bool is_beginning, NEXUS_PlaybackLoopMode mode, const bmedia_player_bounds *bounds); |
|---|
| 475 | void b_play_media_time_test(void); |
|---|
| 476 | void b_play_media_send_meta(NEXUS_PlaybackHandle p); |
|---|
| 477 | NEXUS_Error b_play_start_media(NEXUS_PlaybackHandle playback, NEXUS_FilePlayHandle file, const NEXUS_PlaypumpStatus *playpump_status,const NEXUS_PlaybackStartSettings *params); |
|---|
| 478 | void b_play_stop_media(NEXUS_PlaybackHandle playback); |
|---|
| 479 | |
|---|
| 480 | void b_play_flush(NEXUS_PlaybackHandle playback); |
|---|
| 481 | void b_play_trick_get(NEXUS_PlaybackHandle p, b_trick_settings *cfg); |
|---|
| 482 | NEXUS_Error b_play_trick_set(NEXUS_PlaybackHandle p, const b_trick_settings *cfg); |
|---|
| 483 | NEXUS_Error b_play_trick_set_pid(NEXUS_PlaybackHandle playback, const NEXUS_Playback_P_PidChannel *pid, const b_trick_settings *settings); |
|---|
| 484 | NEXUS_Error b_play_trick_frameadvance(NEXUS_PlaybackHandle p); |
|---|
| 485 | void b_play_trick_init(NEXUS_PlaybackHandle p); |
|---|
| 486 | void b_play_trick_shutdown(NEXUS_PlaybackHandle p); |
|---|
| 487 | void b_play_update_media_player_config(NEXUS_PlaybackHandle p, bmedia_player_decoder_config *config); |
|---|
| 488 | |
|---|
| 489 | void bplay_get_decode_mark(NEXUS_PlaybackHandle playback, uint32_t *pFifoMarker, unsigned *pCdbDepth); |
|---|
| 490 | |
|---|
| 491 | NEXUS_Error bplay_p_play(NEXUS_PlaybackHandle p, bool *restart, bool flush); |
|---|
| 492 | NEXUS_Error bplay_p_play_from(NEXUS_PlaybackHandle p, bmedia_player_pos position); |
|---|
| 493 | |
|---|
| 494 | NEXUS_Error bplay_p_pause(NEXUS_PlaybackHandle p); |
|---|
| 495 | void bplay_p_clear_buffer(NEXUS_PlaybackHandle p); |
|---|
| 496 | |
|---|
| 497 | void NEXUS_Playback_P_AbortPlayback(NEXUS_PlaybackHandle p); |
|---|
| 498 | |
|---|
| 499 | /* nexus_playback_decoder functions - abstracts decoder api's */ |
|---|
| 500 | NEXUS_Error NEXUS_P_Playback_VideoDecoder_GetStatus(const NEXUS_Playback_P_PidChannel *pid, NEXUS_VideoDecoderStatus *pStatus); |
|---|
| 501 | void NEXUS_P_Playback_VideoDecoder_GetTrickState(const NEXUS_Playback_P_PidChannel *pid, NEXUS_VideoDecoderTrickState *pState); |
|---|
| 502 | NEXUS_Error NEXUS_P_Playback_VideoDecoder_SetTrickState(const NEXUS_Playback_P_PidChannel *pid, const NEXUS_VideoDecoderTrickState *pState); |
|---|
| 503 | void NEXUS_P_Playback_VideoDecoder_GetPlaybackSettings(const NEXUS_Playback_P_PidChannel *pid, NEXUS_VideoDecoderPlaybackSettings *pSettings); |
|---|
| 504 | NEXUS_Error NEXUS_P_Playback_VideoDecoder_SetPlaybackSettings(const NEXUS_Playback_P_PidChannel *pid, const NEXUS_VideoDecoderPlaybackSettings *pSettings); |
|---|
| 505 | void NEXUS_P_Playback_VideoDecoder_Flush(const NEXUS_Playback_P_PidChannel *pid); |
|---|
| 506 | NEXUS_Error NEXUS_P_Playback_AudioDecoder_GetStatus(const NEXUS_Playback_P_PidChannel *pid, NEXUS_AudioDecoderStatus *pStatus); |
|---|
| 507 | NEXUS_Error NEXUS_Playback_P_AudioDecoder_Advance(const NEXUS_Playback_P_PidChannel *pid, uint32_t video_pts); |
|---|
| 508 | void NEXUS_P_Playback_AudioDecoder_Flush(const NEXUS_Playback_P_PidChannel *pid); |
|---|
| 509 | void NEXUS_P_Playback_AudioDecoder_GetTrickState(const NEXUS_Playback_P_PidChannel *pid, NEXUS_AudioDecoderTrickState *pState); |
|---|
| 510 | NEXUS_Error NEXUS_P_Playback_AudioDecoder_SetTrickState(const NEXUS_Playback_P_PidChannel *pid, NEXUS_AudioDecoderTrickState *pState); |
|---|
| 511 | NEXUS_Error b_play_getpts(NEXUS_PlaybackHandle p, uint32_t *pts); |
|---|
| 512 | bool b_play_decoders_in_tsm_mode(NEXUS_PlaybackHandle playback); |
|---|
| 513 | const NEXUS_Playback_P_PidChannel *b_play_get_video_decoder(NEXUS_PlaybackHandle playback); |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | /* callbacks from decoders */ |
|---|
| 517 | void NEXUS_Playback_P_VideoDecoderFirstPts(void *context); |
|---|
| 518 | void NEXUS_Playback_P_VideoDecoderFirstPtsPassed(void *context); |
|---|
| 519 | |
|---|
| 520 | #define b_imin(x,y) ((x)<(y) ? (x):(y)) |
|---|
| 521 | |
|---|
| 522 | #ifdef __cplusplus |
|---|
| 523 | } |
|---|
| 524 | #endif |
|---|
| 525 | |
|---|
| 526 | #endif /* NEXUS_PLAYBACK_IMPL_H__ */ |
|---|
| 527 | |
|---|