1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef __MEDIA_CLOCK_CONVERTER_H 19 #define __MEDIA_CLOCK_CONVERTER_H 20 21 #include "oscl_base.h" 22 23 #ifndef OSCL_EXCEPTION_H_INCLUDED 24 #include "oscl_exception.h" 25 #endif 26 27 const uint32 WRAP_THRESHOLD = 0x80000000; 28 const uint32 MISORDER_THRESHOLD = 0x80000000; 29 30 class MediaClockConverter 31 { 32 33 public: 34 MediaClockConverter(uint32 in_timescale = 1, uint32 init_ts = 0) 35 { 36 // Timescale value cannot be zero 37 OSCL_ASSERT(in_timescale != 0); 38 if (0 == in_timescale) 39 { 40 OSCL_LEAVE(OsclErrArgument); 41 } 42 timescale = in_timescale; 43 current_ts = init_ts; 44 wrap_count = 0; 45 }; 46 MediaClockConverter(const MediaClockConverter & a)47 MediaClockConverter(const MediaClockConverter& a) 48 { 49 // Timescale value cannot be zero 50 OSCL_ASSERT(a.timescale != 0); 51 if (0 == a.timescale) 52 { 53 OSCL_LEAVE(OsclErrCorrupt); 54 } 55 timescale = a.timescale; 56 current_ts = a.current_ts; 57 wrap_count = a.wrap_count; 58 }; 59 60 /** 61 * The assignment operator 62 */ 63 MediaClockConverter& operator=(const MediaClockConverter& a) 64 { 65 if (&a != this) 66 { 67 // Timescale value cannot be zero 68 OSCL_ASSERT(a.timescale != 0); 69 if (0 == a.timescale) 70 { 71 OSCL_LEAVE(OsclErrCorrupt); 72 } 73 timescale = a.timescale; 74 current_ts = a.current_ts; 75 wrap_count = a.wrap_count; 76 } 77 return *this; 78 }; 79 set_clock(uint32 init_ts,uint32 in_wrap_count)80 void set_clock(uint32 init_ts, uint32 in_wrap_count) 81 { 82 current_ts = init_ts; 83 84 // Timescale value cannot be zero 85 OSCL_ASSERT(timescale != 0); 86 if (0 == timescale) 87 { 88 OSCL_LEAVE(OsclErrCorrupt); 89 } 90 wrap_count = in_wrap_count % timescale; 91 }; 92 93 // set the clock with value from another timescale 94 OSCL_IMPORT_REF void set_clock_other_timescale(uint32 value, uint32 timescale); 95 96 OSCL_IMPORT_REF void set_timescale(uint32 new_timescale); 97 98 OSCL_IMPORT_REF bool update_clock(uint32 new_ts); 99 100 OSCL_IMPORT_REF uint32 get_timediff_and_update_clock(uint32 value, uint32 timescale, 101 uint32 output_timescale); 102 103 OSCL_IMPORT_REF uint32 get_timediff_and_update_clock(uint32 value, 104 uint32 output_timescale); 105 106 OSCL_IMPORT_REF uint32 get_converted_ts(uint32 new_timscale) const; get_wrap_count()107 OSCL_IMPORT_REF uint32 get_wrap_count() const 108 { 109 return wrap_count; 110 }; get_current_timestamp()111 OSCL_IMPORT_REF uint32 get_current_timestamp() const 112 { 113 return current_ts; 114 }; get_timescale()115 OSCL_IMPORT_REF uint32 get_timescale() const 116 { 117 return timescale; 118 }; 119 120 OSCL_IMPORT_REF void set_value(const MediaClockConverter& src); 121 122 private: 123 uint32 timescale; 124 uint32 current_ts; 125 uint32 wrap_count; 126 }; 127 128 129 130 131 #endif 132