1 /*
2 * Copyright (C) 2020 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/MediaCodec.h>
18 #include <media/stagefright/MediaCodecListWriter.h>
19
20 #include "MediaTestHelper.h"
21
22 namespace android {
23
24 // static
CreateCodec(const AString & name,const sp<ALooper> & looper,std::function<sp<CodecBase> (const AString &,const char *)> getCodecBase,std::function<status_t (const AString &,sp<MediaCodecInfo> *)> getCodecInfo)25 sp<MediaCodec> MediaTestHelper::CreateCodec(
26 const AString &name,
27 const sp<ALooper> &looper,
28 std::function<sp<CodecBase>(const AString &, const char *)> getCodecBase,
29 std::function<status_t(const AString &, sp<MediaCodecInfo> *)> getCodecInfo) {
30 sp<MediaCodec> codec = new MediaCodec(
31 looper, MediaCodec::kNoPid, MediaCodec::kNoUid, getCodecBase, getCodecInfo);
32 if (codec->init(name) != OK) {
33 return nullptr;
34 }
35 return codec;
36 }
37
38 // static
Reclaim(const sp<MediaCodec> & codec,bool force)39 void MediaTestHelper::Reclaim(const sp<MediaCodec> &codec, bool force) {
40 codec->reclaim(force);
41 }
42
43 // static
CreateCodecListWriter()44 std::shared_ptr<MediaCodecListWriter> MediaTestHelper::CreateCodecListWriter() {
45 return std::shared_ptr<MediaCodecListWriter>(new MediaCodecListWriter);
46 }
47
48 // static
WriteCodecInfos(const std::shared_ptr<MediaCodecListWriter> & writer,std::vector<sp<MediaCodecInfo>> * codecInfos)49 void MediaTestHelper::WriteCodecInfos(
50 const std::shared_ptr<MediaCodecListWriter> &writer,
51 std::vector<sp<MediaCodecInfo>> *codecInfos) {
52 writer->writeCodecInfos(codecInfos);
53 }
54
55 } // namespace android
56