1 /*
2 * Copyright 2017, 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 #include <media/stagefright/RemoteMediaExtractor.h>
18 #include <media/stagefright/RemoteMediaSource.h>
19 #include <media/IMediaSource.h>
20
21 namespace android {
22
RemoteMediaSource(const sp<RemoteMediaExtractor> & extractor,MediaTrack * source,const sp<RefBase> & plugin)23 RemoteMediaSource::RemoteMediaSource(
24 const sp<RemoteMediaExtractor> &extractor,
25 MediaTrack *source,
26 const sp<RefBase> &plugin)
27 : mExtractor(extractor),
28 mSource(source),
29 mExtractorPlugin(plugin) {}
30
~RemoteMediaSource()31 RemoteMediaSource::~RemoteMediaSource() {
32 delete mSource;
33 mExtractorPlugin = nullptr;
34 }
35
start(MetaData * params)36 status_t RemoteMediaSource::start(MetaData *params) {
37 return mSource->start(params);
38 }
39
stop()40 status_t RemoteMediaSource::stop() {
41 return mSource->stop();
42 }
43
getFormat()44 sp<MetaData> RemoteMediaSource::getFormat() {
45 sp<MetaData> meta = new MetaData();
46 if (mSource->getFormat(*meta.get()) == OK) {
47 return meta;
48 }
49 return nullptr;
50 }
51
read(MediaBufferBase ** buffer,const MediaSource::ReadOptions * options)52 status_t RemoteMediaSource::read(
53 MediaBufferBase **buffer, const MediaSource::ReadOptions *options) {
54 return mSource->read(buffer, reinterpret_cast<const MediaSource::ReadOptions*>(options));
55 }
56
pause()57 status_t RemoteMediaSource::pause() {
58 return ERROR_UNSUPPORTED;
59 }
60
setStopTimeUs(int64_t)61 status_t RemoteMediaSource::setStopTimeUs(int64_t /* stopTimeUs */) {
62 return ERROR_UNSUPPORTED;
63 }
64
65 ////////////////////////////////////////////////////////////////////////////////
66
67 // static
wrap(const sp<RemoteMediaExtractor> & extractor,MediaTrack * source,const sp<RefBase> & plugin)68 sp<IMediaSource> RemoteMediaSource::wrap(
69 const sp<RemoteMediaExtractor> &extractor,
70 MediaTrack *source, const sp<RefBase> &plugin) {
71 if (source == nullptr) {
72 return nullptr;
73 }
74 return new RemoteMediaSource(extractor, source, plugin);
75 }
76
77 } // namespace android
78