2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
20 namespace Tizen.Multimedia.MediaCodec
22 internal static partial class Interop
24 internal static class MediaCodec
26 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27 internal delegate void InputBufferUsedCallback(IntPtr mediaPacket, IntPtr arg);
29 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
30 internal delegate void OutputBufferAvailableCallback(IntPtr mediaPacket, IntPtr arg);
32 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33 internal delegate void ErrorCallback(int errorCode, IntPtr arg);
35 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
36 internal delegate void EosCallback(IntPtr arg);
38 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
39 internal delegate void BufferStatusCallback(int statusCode, IntPtr arg);
41 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
42 internal delegate bool SupportedCodecCallback(int codecType, IntPtr arg);
44 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_create")]
45 internal static extern int Create(out IntPtr handle);
47 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_destroy")]
48 internal static extern int Destroy(IntPtr handle);
50 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_codec")]
51 internal static extern int Configure(IntPtr handle, int codecType, int flags);
53 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_vdec_info")]
54 internal static extern int SetVideoDecoderInfo(IntPtr handle, int width, int height);
56 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_venc_info")]
57 internal static extern int SetVideoEncoderInfo(IntPtr handle, int width, int height,
58 int fps, int targetBits);
60 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_adec_info")]
61 internal static extern int SetAudioDecoderInfo(IntPtr handle, int sampleRate, int channel,
64 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_aenc_info")]
65 internal static extern int SetAudioEncoderInfo(IntPtr handle, int sampleRate, int channel,
66 int bit, int bitRate);
68 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_prepare")]
69 internal static extern int Prepare(IntPtr handle);
71 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unprepare")]
72 internal static extern int Unprepare(IntPtr handle);
74 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_process_input")]
75 internal static extern int Process(IntPtr handle, IntPtr mediaPacket, ulong timeoutInUs);
77 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_get_output")]
78 internal static extern int GetOutput(IntPtr handle, out IntPtr packet, ulong timeoutInUs);
80 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_flush_buffers")]
81 internal static extern int FlushBuffers(IntPtr handle);
83 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_input_buffer_used_cb")]
84 internal static extern int SetInputBufferUsedCb(IntPtr handle,
85 InputBufferUsedCallback cb, IntPtr arg = default(IntPtr));
87 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_input_buffer_used_cb")]
88 internal static extern int UnsetInputBufferUsedCb(IntPtr handle);
90 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_output_buffer_available_cb")]
91 internal static extern int SetOutputBufferAvailableCb(IntPtr handle,
92 OutputBufferAvailableCallback cb, IntPtr arg = default(IntPtr));
94 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_output_buffer_available_cb")]
95 internal static extern int UnsetOutputBufferAvailableCb(IntPtr handle);
97 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_error_cb")]
98 internal static extern int SetErrorCb(IntPtr handle, ErrorCallback cb, IntPtr arg = default(IntPtr));
100 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_error_cb")]
101 internal static extern int UnsetErrorCb(IntPtr handle);
103 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_eos_cb")]
104 internal static extern int SetEosCb(IntPtr handle, EosCallback cb, IntPtr arg = default(IntPtr));
106 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_eos_cb")]
107 internal static extern int UnsetEosCb(IntPtr handle);
109 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_buffer_status_cb")]
110 internal static extern int SetBufferStatusCb(IntPtr handle, BufferStatusCallback cb,
111 IntPtr arg = default(IntPtr));
113 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_buffer_status_cb")]
114 internal static extern int UnsetBufferStatusCb(IntPtr handle);
116 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_get_supported_type")]
117 internal static extern int GetSupportedType(IntPtr handle, int codecType, bool isEncoder,
120 [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_foreach_supported_codec_static")]
121 internal static extern int ForeachSupportedCodec(SupportedCodecCallback cb, IntPtr arg);