• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 MEDIA_ADAPTER_H
18 #define MEDIA_ADAPTER_H
19 
20 #include <media/stagefright/MediaSource.h>
21 #include <media/stagefright/foundation/ABase.h>
22 #include <media/stagefright/MediaBuffer.h>
23 #include <media/stagefright/MetaData.h>
24 #include <utils/threads.h>
25 
26 namespace android {
27 
28 // Convert the MediaMuxer's push model into MPEG4Writer's pull model.
29 // Used only by the MediaMuxer for now.
30 struct MediaAdapter : public MediaSource, public MediaBufferObserver {
31 public:
32     // MetaData is used to set the format and returned at getFormat.
33     MediaAdapter(const sp<MetaData> &meta);
34     virtual ~MediaAdapter();
35     /////////////////////////////////////////////////
36     // Inherited functions from MediaSource
37     /////////////////////////////////////////////////
38 
39     virtual status_t start(MetaData *params = NULL);
40     virtual status_t stop();
41     virtual sp<MetaData> getFormat();
42     virtual status_t read(
43             MediaBufferBase **buffer, const ReadOptions *options = NULL);
44 
45     /////////////////////////////////////////////////
46     // Inherited functions from MediaBufferObserver
47     /////////////////////////////////////////////////
48 
49     virtual void signalBufferReturned(MediaBufferBase *buffer);
50 
51     /////////////////////////////////////////////////
52     // Non-inherited functions:
53     /////////////////////////////////////////////////
54 
55     // pushBuffer() will wait for the read() finish, and read() will have a
56     // deep copy, such that after pushBuffer return, the buffer can be re-used.
57     status_t pushBuffer(MediaBuffer *buffer);
58 
59 private:
60     Mutex mAdapterLock;
61     std::mutex mBufferGatingMutex;
62     // Make sure the read() wait for the incoming buffer.
63     Condition mBufferReadCond;
64     // Make sure the pushBuffer() wait for the current buffer consumed.
65     Condition mBufferReturnedCond;
66 
67     MediaBuffer *mCurrentMediaBuffer;
68 
69     bool mStarted;
70     sp<MetaData> mOutputFormat;
71 
72     DISALLOW_EVIL_CONSTRUCTORS(MediaAdapter);
73 };
74 
75 }  // namespace android
76 
77 #endif  // MEDIA_ADAPTER_H
78