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 mTrack(source),
29 mExtractorPlugin(plugin) {}
30
~RemoteMediaSource()31 RemoteMediaSource::~RemoteMediaSource() {
32 delete mTrack;
33 mExtractorPlugin = nullptr;
34 }
35
start(MetaData * params)36 status_t RemoteMediaSource::start(MetaData *params) {
37 if (params) {
38 ALOGW("dropping start parameters:");
39 params->dumpToLog();
40 }
41 return mTrack->start();
42 }
43
stop()44 status_t RemoteMediaSource::stop() {
45 return mTrack->stop();
46 }
47
getFormat()48 sp<MetaData> RemoteMediaSource::getFormat() {
49 sp<MetaData> meta = new MetaData();
50 if (mTrack->getFormat(*meta.get()) == OK) {
51 return meta;
52 }
53 return nullptr;
54 }
55
read(MediaBufferBase ** buffer,const MediaSource::ReadOptions * options)56 status_t RemoteMediaSource::read(
57 MediaBufferBase **buffer, const MediaSource::ReadOptions *options) {
58 return mTrack->read(buffer, reinterpret_cast<const MediaSource::ReadOptions*>(options));
59 }
60
supportNonblockingRead()61 bool RemoteMediaSource::supportNonblockingRead() {
62 return mTrack->supportNonblockingRead();
63 }
64
pause()65 status_t RemoteMediaSource::pause() {
66 return ERROR_UNSUPPORTED;
67 }
68
setStopTimeUs(int64_t)69 status_t RemoteMediaSource::setStopTimeUs(int64_t /* stopTimeUs */) {
70 return ERROR_UNSUPPORTED;
71 }
72
73 ////////////////////////////////////////////////////////////////////////////////
74
75 // static
wrap(const sp<RemoteMediaExtractor> & extractor,MediaTrack * source,const sp<RefBase> & plugin)76 sp<IMediaSource> RemoteMediaSource::wrap(
77 const sp<RemoteMediaExtractor> &extractor,
78 MediaTrack *source, const sp<RefBase> &plugin) {
79 if (source == nullptr) {
80 return nullptr;
81 }
82 return new RemoteMediaSource(extractor, source, plugin);
83 }
84
85 } // namespace android
86