Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: media/base/android/ndk_media_codec_wrapper.cc

Issue 2672313006: media: Remove the unused NdkMediaCodecBridge (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // The file defines the symbols from NDKMediaCodec that android is using. It
6 // then loads the library dynamically on first use.
7
8 #include <media/NdkMediaCodec.h>
9 #include <media/NdkMediaFormat.h>
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include "base/files/file_path.h"
14 #include "base/logging.h"
15 #include "base/native_library.h"
16
17 #define LOOKUP_FUNC(func_name, return_type, args, arg_names) \
18 return_type func_name args { \
19 typedef return_type(*signature) args; \
20 static signature g_##func_name = \
21 reinterpret_cast<signature>(base::GetFunctionPointerFromNativeLibrary( \
22 LibraryHandle(), #func_name)); \
23 return g_##func_name arg_names; \
24 }
25
26 // The constants used in chromium. Those symbols are defined as extern symbols
27 // in the NdkMediaFormat headers. They will be initialized to their correct
28 // values when the library is loaded.
29 const char* AMEDIAFORMAT_KEY_CHANNEL_COUNT;
30 const char* AMEDIAFORMAT_KEY_HEIGHT;
31 const char* AMEDIAFORMAT_KEY_SAMPLE_RATE;
32 const char* AMEDIAFORMAT_KEY_WIDTH;
33
34 namespace {
35
36 // The name of the library to load.
37 const char kMediaNDKLibraryName[] = "libmediandk.so";
38
39 // Loads the OpenSLES library, and initializes all the proxies.
40 base::NativeLibrary IntializeLibraryHandle() {
41 base::NativeLibrary handle =
42 base::LoadNativeLibrary(base::FilePath(kMediaNDKLibraryName), NULL);
43 DCHECK(handle) << "Unable to load " << kMediaNDKLibraryName;
44
45 // Setup the proxy for each symbol.
46 // Attach the symbol name to the proxy address.
47 struct SymbolDefinition {
48 const char* name;
49 const char** value;
50 };
51
52 // The list of defined symbols.
53 const SymbolDefinition kSymbols[] = {
54 {"AMEDIAFORMAT_KEY_CHANNEL_COUNT", &AMEDIAFORMAT_KEY_CHANNEL_COUNT},
55 {"AMEDIAFORMAT_KEY_HEIGHT", &AMEDIAFORMAT_KEY_HEIGHT},
56 {"AMEDIAFORMAT_KEY_SAMPLE_RATE", &AMEDIAFORMAT_KEY_SAMPLE_RATE},
57 {"AMEDIAFORMAT_KEY_WIDTH", &AMEDIAFORMAT_KEY_WIDTH},
58 };
59
60 for (size_t i = 0; i < sizeof(kSymbols) / sizeof(kSymbols[0]); ++i) {
61 memcpy(kSymbols[i].value,
62 base::GetFunctionPointerFromNativeLibrary(handle, kSymbols[i].name),
63 sizeof(char*));
64 DCHECK(*kSymbols[i].value) << "Unable to find symbol for "
65 << kSymbols[i].name;
66 }
67 return handle;
68 }
69
70 // Returns the handler to the shared library. The library itself will be lazily
71 // loaded during the first call to this function.
72 base::NativeLibrary LibraryHandle() {
73 // The handle is lazily initialized on the first call.
74 static base::NativeLibrary g_mediandk_LibraryHandle =
75 IntializeLibraryHandle();
76 return g_mediandk_LibraryHandle;
77 }
78 }
79
80 LOOKUP_FUNC(AMediaCodec_createDecoderByType,
81 AMediaCodec*,
82 (const char* mime_type),
83 (mime_type));
84 LOOKUP_FUNC(AMediaCodec_createEncoderByType,
85 AMediaCodec*,
86 (const char* mime_type),
87 (mime_type));
88 LOOKUP_FUNC(AMediaCodec_delete, media_status_t, (AMediaCodec * codec), (codec));
89 LOOKUP_FUNC(AMediaCodec_configure,
90 media_status_t,
91 (AMediaCodec * codec,
92 const AMediaFormat* format,
93 ANativeWindow* surface,
94 AMediaCrypto* crypto,
95 uint32_t flags),
96 (codec, format, surface, crypto, flags));
97 LOOKUP_FUNC(AMediaCodec_start, media_status_t, (AMediaCodec * codec), (codec));
98 LOOKUP_FUNC(AMediaCodec_stop, media_status_t, (AMediaCodec * codec), (codec));
99 LOOKUP_FUNC(AMediaCodec_flush, media_status_t, (AMediaCodec * codec), (codec));
100 LOOKUP_FUNC(AMediaCodec_getInputBuffer,
101 uint8_t*,
102 (AMediaCodec * codec, size_t idx, size_t* out_size),
103 (codec, idx, out_size));
104 LOOKUP_FUNC(AMediaCodec_getOutputBuffer,
105 uint8_t*,
106 (AMediaCodec * codec, size_t idx, size_t* out_size),
107 (codec, idx, out_size));
108 LOOKUP_FUNC(AMediaCodec_dequeueInputBuffer,
109 ssize_t,
110 (AMediaCodec * codec, int64_t timeoutUs),
111 (codec, timeoutUs));
112 LOOKUP_FUNC(AMediaCodec_queueInputBuffer,
113 media_status_t,
114 (AMediaCodec * codec,
115 size_t idx,
116 off_t offset,
117 size_t size,
118 uint64_t time,
119 uint32_t flags),
120 (codec, idx, offset, size, time, flags));
121 LOOKUP_FUNC(AMediaCodec_queueSecureInputBuffer,
122 media_status_t,
123 (AMediaCodec * codec,
124 size_t idx,
125 off_t offset,
126 AMediaCodecCryptoInfo* cryto,
127 uint64_t time,
128 uint32_t flags),
129 (codec, idx, offset, cryto, time, flags));
130 LOOKUP_FUNC(AMediaCodec_dequeueInputBuffer,
131 ssize_t,
132 (AMediaCodec * codec,
133 AMediaCodecBufferInfo* info,
134 int64_t timeoutUs),
135 (codec, info, timeoutUs));
136 LOOKUP_FUNC(AMediaCodec_dequeueOutputBuffer,
137 ssize_t,
138 (AMediaCodec * codec,
139 AMediaCodecBufferInfo* info,
140 int64_t timeoutUs),
141 (codec, info, timeoutUs));
142 LOOKUP_FUNC(AMediaCodec_getOutputFormat,
143 AMediaFormat*,
144 (AMediaCodec * codec),
145 (codec));
146 LOOKUP_FUNC(AMediaCodec_releaseOutputBuffer,
147 media_status_t,
148 (AMediaCodec * codec, size_t idx, bool render),
149 (codec, idx, render));
150 LOOKUP_FUNC(AMediaCodecCryptoInfo_new,
151 AMediaCodecCryptoInfo*,
152 (int num_subsamples,
153 uint8_t key[16],
154 uint8_t iv[16],
155 cryptoinfo_mode_t mode,
156 size_t* clear_bytes,
157 size_t* encrypted_bytes),
158 (num_subsamples, key, iv, mode, clear_bytes, encrypted_bytes));
159 LOOKUP_FUNC(AMediaCodecCryptoInfo_delete,
160 media_status_t,
161 (AMediaCodecCryptoInfo * info),
162 (info));
163 LOOKUP_FUNC(AMediaFormat_delete,
164 media_status_t,
165 (AMediaFormat * format),
166 (format));
167 LOOKUP_FUNC(AMediaFormat_getInt32,
168 bool,
169 (AMediaFormat * format, const char* name, int32_t* out),
170 (format, name, out));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698