00001 // MPEGDecoder.h - interface of class MPEGDecoder 00002 // 00003 // Copyright (c) 2003, Roku, LLC. 00004 // 00006 00007 #ifndef _ROKU_INCLUDE_DESCHUTES_LIBRARIES_HDMACHINEX225_MPEGDECODER_H 00008 #define _ROKU_INCLUDE_DESCHUTES_LIBRARIES_HDMACHINEX225_MPEGDECODER_H 00009 00010 #include <cascade/CascadeTypedefs.h> 00011 #include <cascade/graphics/CascadeRect.h> 00012 00014 // class MPEGDecoder settings #defines 00015 #define DESCHUTES_MPEGDECODER_SETTINGS_SECTION "deschutes-mpegdecoder" 00016 #define DESCHUTES_MPEGDECODER_VARNAME_AC3PASSTHRU "AC3PassThru" 00017 #define DESCHUTES_MPEGDECODER_AC3PASSTHRU_DEFAULT 0 00018 00020 // class MPEGDecoder 00021 class MPEGDecoder 00022 { 00023 public: 00024 // new EXPERIMENTAL types 00025 enum ClockSource { kClockSourceNone = 0, kExternalA, kExternalB, kAudioPLLA, kAudioPLLB, kVideoClock }; 00026 enum ClockRecoveryMode { kRecoveryModeNone = 0, kOnce, kSoftware, kVideoHardware }; 00027 public: 00028 // new EXPERIMENTAL functions 00029 bool NewOpen( 00030 u32 nNumBuffers = 0, // use internal default 00031 u32 nBufferSizeInBytes = 0, // use internal default 00032 ClockSource videoClockSource = kVideoClock, 00033 ClockRecoveryMode videoClockRecoveryMode = kOnce, 00034 ClockSource audioClockSource = kAudioPLLA, 00035 ClockRecoveryMode audioClockRecoveryMode = kOnce, 00036 bool bEnableFeedThrottling = true, 00037 bool bAttachAudioClockToVideoClock = true, 00038 bool bSynchronizeVideo = true, 00039 bool bSynchronizeAudio = false, 00040 u32 nAudioSyncThreshold = 50 * 90); // 50 ms (in units of 90 kHz) 00041 00042 // notes on nAudioSyncThreshold: 00043 // if bSynchronizeAudio is true, then audio will be presented when |PTS-STC| < nAudioSyncThreshold 00044 00045 public: 00046 MPEGDecoder(); 00047 virtual ~MPEGDecoder(); 00048 00049 public: 00050 bool GetBufferRequirements(u32 & nAlignmentToSet, u32 & nSizeMultipleToSet, u32 & nMaxBuffersToSet); 00051 bool Open(u32 nNumBuffers, u32 nBufferSizeInBytes); 00052 // video player is opened with the number and size of requested buffers 00053 // if either parameter is 0, the default num buffers and buffer size will be selected 00054 bool Close(); 00055 // close the video player as soon as you are done with it so it can be used 00056 // by other clients. 00057 bool IsOpen(); 00058 // returns true if video player is open 00059 00060 virtual u32 OnFillBuffer(u8 * pBuffer, u32 nBuffSize) = 0; 00061 // OnFillBuffer gets called whenever a buffer needs filling 00062 // Clients should fill the buffer with nBuffSize bytes and then 00063 // return the number of actual bytes filled. 00064 // If the returned number of actual bytes is less than nBuffSize, 00065 // then the buffer will be null-padded. 00066 00067 virtual bool OnDecoderError() = 0; 00068 // OnDecoderError() gets called whenever the decoder encounters 00069 // an error while it is running. These errors are usually hardware 00070 // errors. Clients should return true to have the decoder remain streaming 00071 // or false to have the decoder enter the paused streaming state. 00072 00073 bool SelectPIDs(bool bProgramStream, u32 nPCRPID, u32 nVideoPID, u32 nAudioPID, u32 nAudioSSID, bool bAC3Audio); 00074 // call SelectPIDs before or during streaming to select the pids that will 00075 // play back. If any of the parameters are changed from their current settings, 00076 // any data in the pipeline will be streamed through before the change takes effect. 00077 // If any PID passed in is zero, that is interpreted as meaning don't play that stream type. 00078 // e.g. if nAudioPID is zero then audio will not be played back. 00079 // if bProgramStream is true then nPCRPID, nVideoPID, and nAudioPID will be interpreted 00080 // as stream id's, not PIDS. If bProgramStream and bAC3Audio are true and nAudioSSID is non-zero, 00081 // then the substream identified by nAudioSSID will be used. 00082 00083 bool SetOutputAndScaleRects(const CascadeRect & outputRect, const CascadeRect & scaleRect); 00084 // SetOutputAndScaleRects() should be called after every Open() to set the proper 00085 // output resolution and scale rects. (Use the ones gotten from CascadeScreen). 00086 00087 bool PauseStreaming(); 00088 // PauseStreaming() pauses streaming. PauseStreaming takes effect immediately and returns 00089 // true with no effect if streaming is already paused. 00090 bool ResumeStreaming(); 00091 // ResumeStreaming() starts or resumes streaming. Your OnFillBuffer member function will 00092 // get called back in the context of a streamer thread immediately after calling 00093 // ResumeStreaming() the first time. 00094 // If ResumeStreaming is called while streaming is already running, it returns true 00095 // with no effect. 00096 bool FlushStream(bool bDecode = true); 00097 // immediately flushes all pending buffers optionally running them 00098 // through the decoder. Streaming will always be paused after FlushStream() 00099 // is called. 00100 // NOTE: FlushStream is currently not implemented; need to rethink trick modes 00101 // for un-trick decoder. 00102 00103 // NOTE: returning short from OnFillBuffer no longer pauses streaming. 00104 00105 // RenderSingleFrames() 00106 // 00107 // Open(); 00108 // ResumeStreaming(); 00109 // -- fill buffer with 1 frame, return with short size 00110 // ResumeStreaming(); 00111 // -- fill buffer with 1 frame, return with short size 00112 // ResumeStreaming(); 00113 // -- fill buffer with 1 frame, return with short size 00114 00115 // JumpToPositionAndPause() 00116 // 00117 // Open(); 00118 // ResumeStreaming(); 00119 // -- fill buffer with 1 frame from position, return with short size 00120 00121 // JumpToPositionAndPlay() 00122 // 00123 // Open(); 00124 // ResumeStreaming(); 00125 // -- fill buffer with frames starting at position 00126 00127 // JumpToPositionAndPlayNFrames() 00128 // 00129 // Open(); 00130 // ResumeStreaming(); 00131 // -- fill buffer with N frames starting at position 00132 // -- return short size when done 00133 00134 // Variable speed rewind 00135 // 00136 // Open(); 00137 // JumpToPositionAndPlayNFrames(); 00138 // -- decrement position 00139 // JumpToPositionAndPlayNFrames(); 00140 // -- decrement position... 00141 00142 // Variable speed FF 00143 // 00144 // Open(); 00145 // JumpToPositionAndPlayNFrames(); 00146 // -- increment position 00147 // JumpToPositionAndPlayNFrames(); 00148 // -- increment position... 00149 00150 // End one file, play another, no gap 00151 // 00152 // Open(); 00153 // ResumeStreaming(); 00154 // -- fill buffers for first file, when first file read 00155 // -- is over, continue with second file 00156 00157 // Jump from the middle of one file to another, no gap 00158 // 00159 // Open(); 00160 // ResumeStreaming(); 00161 // -- fill buffers, when transfer time comes 00162 00163 // Abort playback of 1 file, play another, no gap 00164 // 00165 // Open(); 00166 // ResumeStreaming(); 00167 // -- fill buffers for first file, when abort point reached: 00168 // FlushStreaming(false); 00169 // ResumeStreaming(); 00170 // -- fill with new file 00171 00172 private: 00173 void * m_pDecoderInternal; 00174 }; 00175 00176 #endif // #ifndef _ROKU_INCLUDE_DESCHUTES_LIBRARIES_HDMACHINEX225_MPEGDECODER_H 00177 00179 // LOG 00181 // 13-Oct-03 dwoodward created 00182 // 24-Oct-03 dwoodward added SetOutputAndScaleRects() 00183 // 14-Nov-03 dwoodward replaced independent pid selection with unified SelectPIDs function. 00184 // 15-Apr-04 dwoodward added new EXPERIMENTAL functions 00185 // 13-Aug-04 dwoodward added nAudioSSID to SelectPIDs. 00186 // 07-Sep-04 dwoodward updated comments to reflect life