1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010-2015, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6     * Redistributions of source code must retain the above copyright
7       notice, this list of conditions and the following disclaimer.
8     * Redistributions in binary form must reproduce the above copyright
9       notice, this list of conditions and the following disclaimer in the
10       documentation and/or other materials provided with the distribution.
11     * Neither the name of The Linux Foundation nor
12       the names of its contributors may be used to endorse or promote
13       products derived from this software without specific prior written
14       permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --------------------------------------------------------------------------*/
28 #ifndef __DTSPARSER_H
29 #define __DTSPARSER_H
30 
31 #include "OMX_Core.h"
32 #include "OMX_QCOMExtns.h"
33 #include "qc_omx_component.h"
34 
35 #include<stdlib.h>
36 
37 #include <stdio.h>
38 #include <inttypes.h>
39 
40 #ifdef _ANDROID_
41 extern "C" {
42 #include<utils/Log.h>
43 }
44 #else
45 #define ALOGE(fmt, args...) fprintf(stderr, fmt, ##args)
46 #endif /* _ANDROID_ */
47 
48 class omx_time_stamp_reorder
49 {
50     class auto_lock {
51         public:
auto_lock(pthread_mutex_t * lock)52             auto_lock(pthread_mutex_t *lock)
53                 : mLock(lock) {
54                     if (mLock)
55                         pthread_mutex_lock(mLock);
56                 }
~auto_lock()57             ~auto_lock() {
58                 if (mLock)
59                     pthread_mutex_unlock(mLock);
60             }
61         private:
62             pthread_mutex_t *mLock;
63     };
64 
65     public:
66         omx_time_stamp_reorder();
67         ~omx_time_stamp_reorder();
68         void set_timestamp_reorder_mode(bool flag);
69         void enable_debug_print(bool flag);
70         bool insert_timestamp(OMX_BUFFERHEADERTYPE *header);
71         bool get_next_timestamp(OMX_BUFFERHEADERTYPE *header, bool is_interlaced);
72         bool remove_time_stamp(OMX_TICKS ts, bool is_interlaced);
73         void flush_timestamp();
74 
75     private:
76 #define TIME_SZ 64
77         typedef struct timestamp {
78             OMX_TICKS timestamps;
79             bool in_use;
80         } timestamp;
81         typedef struct time_stamp_list {
82             timestamp input_timestamps[TIME_SZ];
83             time_stamp_list *next;
84             time_stamp_list *prev;
85             unsigned int entries_filled;
86         } time_stamp_list;
87         bool error;
88         time_stamp_list *phead,*pcurrent;
89         bool get_current_list();
90         bool add_new_list();
91         bool update_head();
92         void delete_list();
handle_error()93         void handle_error() {
94             ALOGE("Error handler called for TS Parser");
95 
96             if (error)
97                 return;
98 
99             error = true;
100             delete_list();
101         }
102         bool reorder_ts;
103         bool print_debug;
104         pthread_mutex_t m_lock;
105 };
106 #endif
107