From: nam <36914158+aferin@users.noreply.github.com> Date: Tue, 16 Jul 2019 07:58:24 +0000 (+0900) Subject: [MediaPlayer] Add API to export audio PCM data (#930) X-Git-Tag: submit/tizen/20190717.005204~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d38463ecb8859124318ce7539f0cc3d6f18317d9;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [MediaPlayer] Add API to export audio PCM data (#930) * [MediaPlayer] Add API to export audio PCM data --- diff --git a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs index f40b77d2d..8c0cf7af0 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs @@ -36,6 +36,9 @@ internal static partial class Interop [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void VideoFrameDecodedCallback(IntPtr packetHandle, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void AudioFrameDecodedCallback(IntPtr packetHandle, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void SubtitleUpdatedCallback(uint duration, string text, IntPtr userData); @@ -172,6 +175,13 @@ internal static partial class Interop [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_video_frame_decoded_cb")] internal static extern PlayerErrorCode UnsetVideoFrameDecodedCb(IntPtr player); + [DllImport(Libraries.Player, EntryPoint = "player_set_media_packet_audio_frame_decoded_cb")] + internal static extern PlayerErrorCode SetAudioFrameDecodedCb(IntPtr player, IntPtr format, PlayerAudioExtractOption opt, + AudioFrameDecodedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_audio_frame_decoded_cb")] + internal static extern PlayerErrorCode UnsetAudioFrameDecodedCb(IntPtr player); + [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_cookie")] internal static extern PlayerErrorCode SetStreamingCookie(IntPtr player, string cookie, int size); diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/AudioDataDecodedEventArgs.cs b/src/Tizen.Multimedia.MediaPlayer/Player/AudioDataDecodedEventArgs.cs new file mode 100644 index 000000000..17a00850c --- /dev/null +++ b/src/Tizen.Multimedia.MediaPlayer/Player/AudioDataDecodedEventArgs.cs @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; + +namespace Tizen.Multimedia +{ + /// + /// Provides data for the event. + /// + /// 6 + public class AudioDataDecodedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the AudioFrameDecodedEventArgs class. + /// + internal AudioDataDecodedEventArgs(MediaPacket packet) + { + Packet = packet; + } + + /// + /// Gets the packet containing the decoded frame. + /// + /// 6 + public MediaPacket Packet { get; } + + } +} diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs index 5d2f5f1ca..ed9f3dc0b 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.Events.cs @@ -169,7 +169,6 @@ namespace Tizen.Multimedia } #region VideoFrameDecoded event - private EventHandler _videoFrameDecoded; private NativePlayer.VideoFrameDecodedCallback _videoFrameDecodedCallback; @@ -223,6 +222,21 @@ namespace Tizen.Multimedia } #endregion + #region AudioFrameDecoded event + /// + /// Occurs when a audio frame is decoded. + /// + /// + /// The event handler will be executed on an internal thread. + /// The in event args should be disposed after use. + /// + /// + /// 6 + public event EventHandler AudioDataDecoded; + + private NativePlayer.AudioFrameDecodedCallback _audioFrameDecodedCallback; + #endregion + private void RegisterVideoStreamChangedCallback() { _videoStreamChangedCallback = (width, height, fps, bitrate, _) => diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs index 604044973..10f939ace 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs @@ -884,7 +884,77 @@ namespace Tizen.Multimedia { Interlocked.Exchange(ref _isPreparing, 0); } - #endregion + + /// + /// Enable to decode an audio data for exporting PCM from a data. + /// + /// The media format handle about required audio PCM specification. + /// The format has to include , + /// and . + /// If the format is NULL, the original PCM format or platform default PCM format will be applied. + /// The audio extract option. + /// The player must be in the state. + /// A event is called in a separate thread(not in the main loop). + /// The audio PCM data can be retrieved using a event as a media packet + /// and it is available until it's destroyed by . + /// The packet has to be destroyed as quickly as possible after rendering the data + /// and all the packets have to be destroyed before is called. + /// The player has already been disposed of. + /// The value is not valid. + /// + /// Operation failed; internal error. + /// -or-
+ /// The player is not in the valid state. + ///
+ /// + /// + /// 6 + public void EnableExportingAudioData(AudioMediaFormat format, PlayerAudioExtractOption option) + { + ValidatePlayerState(PlayerState.Idle); + ValidationUtil.ValidateEnum(typeof(PlayerAudioExtractOption), option, nameof(option)); + + IntPtr formatHandle = IntPtr.Zero; + + _audioFrameDecodedCallback = (IntPtr packetHandle, IntPtr userData) => + { + var handler = AudioDataDecoded; + if (handler != null) + { + Log.Debug(PlayerLog.Tag, "packet : " + packetHandle.ToString()); + handler.Invoke(this, + new AudioDataDecodedEventArgs(MediaPacket.From(packetHandle))); + } + else + { + MediaPacket.From(packetHandle).Dispose(); + } + }; + + formatHandle = format.AsNativeHandle(); + + NativePlayer.SetAudioFrameDecodedCb(Handle, formatHandle, option, _audioFrameDecodedCallback, IntPtr.Zero). + ThrowIfFailed(this, "Failed to register the _audioFrameDecoded"); + } + + /// + /// Disable to decode an audio data. + /// + /// The player must be in the or + /// state. + /// The player has already been disposed of. + /// The player is not in the valid state. + /// + /// 6 + public void DisableExportingAudioData() + { + ValidatePlayerState(PlayerState.Idle, PlayerState.Ready); + + NativePlayer.UnsetAudioFrameDecodedCb(Handle). + ThrowIfFailed(this, "Failed to unset the AudioFrameDecoded"); + + _audioFrameDecodedCallback = null; + } } } diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs index 3a635cedf..a611f1827 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs @@ -295,4 +295,32 @@ namespace Tizen.Multimedia /// Year } + + /// + /// Enumeration of audio extract option. + /// + /// + /// 6 + public enum PlayerAudioExtractOption + { + /// + /// Sync with the playback clock and multichannel audio stream + /// + Default = 0x00, + + /// + /// No sync with the playback clock + /// + NoSyncWithClock = 0x01, + + /// + /// Splits one interleaved multichannel audio stream into many mono audio streams + /// + Deinterleave = 0x02, + + /// + /// No sync with clock and splits into mono streams + /// + NoSyncAndDeinterleave = 0x03, + } }