1 /*
2 * Copyright (C) 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 "include/CallbackDataSource.h"
18
19 #include <media/stagefright/CallbackMediaSource.h>
20 #include <media/stagefright/InterfaceUtils.h>
21 #include <media/stagefright/RemoteDataSource.h>
22 #include <media/stagefright/RemoteMediaSource.h>
23
24 namespace android {
25
CreateDataSourceFromIDataSource(const sp<IDataSource> & source)26 sp<DataSource> CreateDataSourceFromIDataSource(const sp<IDataSource> &source) {
27 if (source == nullptr) {
28 return nullptr;
29 }
30 return new TinyCacheSource(new CallbackDataSource(source));
31 }
32
CreateIDataSourceFromDataSource(const sp<DataSource> & source)33 sp<IDataSource> CreateIDataSourceFromDataSource(const sp<DataSource> &source) {
34 if (source == nullptr) {
35 return nullptr;
36 }
37 return RemoteDataSource::wrap(source);
38 }
39
CreateIMediaExtractorFromMediaExtractor(MediaExtractor * extractor,const sp<DataSource> & source,const sp<RefBase> & plugin)40 sp<IMediaExtractor> CreateIMediaExtractorFromMediaExtractor(
41 MediaExtractor *extractor,
42 const sp<DataSource> &source,
43 const sp<RefBase> &plugin) {
44 if (extractor == nullptr) {
45 return nullptr;
46 }
47 return RemoteMediaExtractor::wrap(extractor, source, plugin);
48 }
49
CreateMediaSourceFromIMediaSource(const sp<IMediaSource> & source)50 sp<MediaSource> CreateMediaSourceFromIMediaSource(const sp<IMediaSource> &source) {
51 if (source == nullptr) {
52 return nullptr;
53 }
54 return new CallbackMediaSource(source);
55 }
56
CreateIMediaSourceFromMediaSourceBase(const sp<RemoteMediaExtractor> & extractor,MediaTrack * source,const sp<RefBase> & plugin)57 sp<IMediaSource> CreateIMediaSourceFromMediaSourceBase(
58 const sp<RemoteMediaExtractor> &extractor,
59 MediaTrack *source, const sp<RefBase> &plugin) {
60 if (source == nullptr) {
61 return nullptr;
62 }
63 return RemoteMediaSource::wrap(extractor, source, plugin);
64 }
65
66 } // namespace android
67