• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
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 express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __DECODER_PUMP_H__
18 #define __DECODER_PUMP_H__
19 
20 #include <pthread.h>
21 
22 #include <common_time/cc_helper.h>
23 #include <media/stagefright/MediaSource.h>
24 #include <utils/LinearTransform.h>
25 #include <utils/List.h>
26 #include <utils/threads.h>
27 
28 namespace android {
29 
30 class MetaData;
31 class OMXClient;
32 class TimedAudioTrack;
33 
34 class AAH_DecoderPump : public MediaSource {
35   public:
36     explicit AAH_DecoderPump(OMXClient& omx);
37     status_t initCheck();
38 
39     status_t queueForDecode(MediaBuffer* buf);
40 
41     status_t init(const sp<MetaData>& params);
42     status_t shutdown();
43 
44     void setRenderTSTransform(const LinearTransform& trans);
45     void setRenderVolume(uint8_t volume);
46     bool isAboutToUnderflow(int64_t threshold);
getStatus()47     bool getStatus() const { return thread_status_; }
48 
49     // MediaSource methods
start(MetaData * params)50     virtual status_t     start(MetaData *params) { return OK; }
getFormat()51     virtual sp<MetaData> getFormat() { return format_; }
stop()52     virtual status_t     stop() { return OK; }
53     virtual status_t     read(MediaBuffer **buffer,
54                               const ReadOptions *options);
55 
56   protected:
57     virtual ~AAH_DecoderPump();
58 
59   private:
60     class ThreadWrapper : public Thread {
61       public:
62         friend class AAH_DecoderPump;
63         explicit ThreadWrapper(AAH_DecoderPump* owner);
64 
65       private:
66         virtual bool threadLoop();
67         AAH_DecoderPump* owner_;
68 
69         DISALLOW_EVIL_CONSTRUCTORS(ThreadWrapper);
70     };
71 
72     void* workThread();
73     virtual status_t shutdown_l();
74     void queueToRenderer(MediaBuffer* decoded_sample);
75     void stopAndCleanupRenderer();
76 
77     sp<MetaData>        format_;
78     int32_t             format_channels_;   // channel count, not channel mask
79     int32_t             format_sample_rate_;
80 
81     sp<MediaSource>     decoder_;
82     OMXClient&          omx_;
83     Mutex               init_lock_;
84 
85     sp<ThreadWrapper>   thread_;
86     Condition           thread_cond_;
87     Mutex               thread_lock_;
88     status_t            thread_status_;
89 
90     Mutex               render_lock_;
91     TimedAudioTrack*    renderer_;
92     bool                last_queued_pts_valid_;
93     int64_t             last_queued_pts_;
94     bool                last_ts_transform_valid_;
95     LinearTransform     last_ts_transform_;
96     uint8_t             last_volume_;
97     CCHelper            cc_helper_;
98 
99     // protected by the thread_lock_
100     typedef List<MediaBuffer*> MBQueue;
101     MBQueue in_queue_;
102 
103     DISALLOW_EVIL_CONSTRUCTORS(AAH_DecoderPump);
104 };
105 
106 }  // namespace android
107 #endif  // __DECODER_PUMP_H__
108