From 341f1e82ef59a528f3d8553976457689d1ab5f8b Mon Sep 17 00:00:00 2001 From: zhangwenting15 Date: Thu, 24 Jul 2025 17:16:37 +0800 Subject: [PATCH] add import Signed-off-by: zhangwenting15 Change-Id: I164b3db3a5a46e5f9265774ffa4387844e9b1e81 --- frameworks/taihe/BUILD.gn | 19 + .../idl/ohos.multimedia.media.context.taihe | 1 + .../taihe/idl/ohos.multimedia.media.taihe | 316 ++++++----- frameworks/taihe/idl/soundPool.taihe | 40 +- frameworks/taihe/idl/systemTonePlayer.taihe | 4 + .../media/include/avimagegenerator_taihe.h | 6 + .../media/include/avmetadataextractor_taihe.h | 5 +- .../media/include/avplayer_callback_taihe.h | 2 + .../taihe/media/include/avplayer_taihe.h | 101 ++-- .../media/include/avrecorder_callback_taihe.h | 11 + .../taihe/media/include/avrecorder_taihe.h | 35 +- .../media/include/avscreen_capture_taihe.h | 2 +- .../taihe/media/include/avtranscoder_taihe.h | 8 +- .../helper_data_source_callback_taihe.h | 2 +- .../media_source_loading_request_taihe.h | 2 +- .../taihe/media/include/media_source_taihe.h | 5 +- .../taihe/media/include/media_taihe_utils.h | 8 +- .../media/src/avimagegenerator_taihe.cpp | 39 +- .../media/src/avmetadataextractor_taihe.cpp | 51 +- .../media/src/avplayer_callback_taihe.cpp | 246 ++++++++- frameworks/taihe/media/src/avplayer_taihe.cpp | 505 +++++++++++++++--- .../media/src/avrecorder_callback_taihe.cpp | 174 ++++++ .../taihe/media/src/avrecorder_taihe.cpp | 459 ++++++++++++++-- .../media/src/avscreen_capture_taihe.cpp | 6 +- .../media/src/avtranscoder_callback_taihe.cpp | 6 +- .../taihe/media/src/avtranscoder_taihe.cpp | 16 +- .../src/helper_data_source_callback_taihe.cpp | 7 +- .../media_source_loader_callback_taihe.cpp | 22 +- .../media_source_loading_request_taihe.cpp | 8 +- .../taihe/media/src/media_source_taihe.cpp | 12 +- .../taihe/media/src/media_taihe_utils.cpp | 87 ++- .../soundpool/include/sound_pool_taihe.h | 26 +- .../src/sound_pool_callback_taihe.cpp | 8 +- .../taihe/soundpool/src/sound_pool_taihe.cpp | 52 +- 34 files changed, 1809 insertions(+), 482 deletions(-) diff --git a/frameworks/taihe/BUILD.gn b/frameworks/taihe/BUILD.gn index 3aab6ae9e..e8b89419b 100644 --- a/frameworks/taihe/BUILD.gn +++ b/frameworks/taihe/BUILD.gn @@ -14,6 +14,7 @@ import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimedia/player_framework/config.gni") import("./../../multimedia_player_framework_aafwk.gni") subsystem_name = "multimedia" @@ -25,6 +26,11 @@ copy_taihe_idl("copy_media_taihe") { sources = [ "//foundation/multimedia/player_framework/frameworks/taihe/idl/ohos.multimedia.media.taihe", "//foundation/multimedia/player_framework/frameworks/taihe/idl/ohos.multimedia.media.context.taihe", ] deps = [ ":copy_soundpool_taihe" ] + external_deps = [ "image_framework:copy_image_taihe", + "audio_framework:copy_taihe",] + if (player_framework_support_drm) { + external_deps += [ "drm_framework:copy_drm_taihe" ] + } } ohos_taihe("run_media_taihe") { @@ -107,6 +113,7 @@ taihe_shared_library("soundpool_taihe") { "hitrace:hitrace_meter", "image_framework:image", "image_framework:image_native", + "image_framework:image_taihe", "ipc:ipc_core", "ipc:ipc_single", "media_foundation:media_foundation", @@ -183,6 +190,7 @@ taihe_shared_library("media_taihe") { "hitrace:hitrace_meter", "image_framework:image", "image_framework:image_native", + "image_framework:image_taihe", "ipc:ipc_core", "ipc:ipc_single", "media_foundation:media_foundation", @@ -190,6 +198,17 @@ taihe_shared_library("media_taihe") { "runtime_core:ani", "window_manager:libdm", ] + + if (player_framework_support_drm) { + external_deps += [ + "drm_framework:drm_framework", + "drm_framework:drm_taihe", + ] + } + + if (player_framework_support_auto_create_file) { + external_deps += ["media_library:medialibrary_ani_utils"] + } } generate_static_abc("media_taihe_abc") { diff --git a/frameworks/taihe/idl/ohos.multimedia.media.context.taihe b/frameworks/taihe/idl/ohos.multimedia.media.context.taihe index 86d403d3b..629f25bc0 100644 --- a/frameworks/taihe/idl/ohos.multimedia.media.context.taihe +++ b/frameworks/taihe/idl/ohos.multimedia.media.context.taihe @@ -17,6 +17,7 @@ @!sts_inject(""" import audio from '@ohos.multimedia.audio'; +import drm from '@ohos.multimedia.drm'; import { BusinessError, ErrorCallback, AsyncCallback, Callback } from '@ohos.base'; import photoAccessHelper from '@ohos.file.photoAccessHelper'; """) diff --git a/frameworks/taihe/idl/ohos.multimedia.media.taihe b/frameworks/taihe/idl/ohos.multimedia.media.taihe index 3a8cf552f..673c256d8 100644 --- a/frameworks/taihe/idl/ohos.multimedia.media.taihe +++ b/frameworks/taihe/idl/ohos.multimedia.media.taihe @@ -23,17 +23,20 @@ static { loadLibrary("media_taihe.z"); } loadLibrary("soundpool_taihe.z"); """) +use ohos.multimedia.image.image as image; +use ohos.multimedia.audio as audio; +use ohos.multimedia.drm as drm; from soundPool use PlayParameters; from soundPool use SoundPool; struct AVFileDescriptor { - fd: f64; - offset: Optional; - length: Optional; + fd: i32; + offset: Optional; + length: Optional; } struct AVDataSrcDescriptor { - fileSize: f64; - callback: (buffer: @arraybuffer Array, length: f64, pos: Optional) => f64; + fileSize: i64; + callback: (buffer: @arraybuffer Array, length: i64, @optional pos: Optional) => i32; } @gen_async("createAVImageGenerator") @@ -53,7 +56,7 @@ function GetScreenCaptureMonitorSync(): Optional; @gen_async("createSoundPool") @gen_promise("createSoundPool") -function CreateSoundPoolSync(maxStreams: f64, audioRendererInfo: @sts_type("audio.AudioRendererInfo") Opaque): Optional; +function CreateSoundPoolSync(maxStreams: i32, audioRendererInfo: @sts_type("audio.AudioRendererInfo") Opaque): Optional; @gen_async("createVideoRecorder") @gen_promise("createVideoRecorder") @@ -73,7 +76,7 @@ function CreateMediaSourceWithUrl(url: String, headers: Optional<@record Map): Optional; @gen_promise("reportAVScreenCaptureUserChoice") -function ReportAVScreenCaptureUserChoiceSync(sessionId: f64, choice: String): void; +function ReportAVScreenCaptureUserChoiceSync(sessionId: i32, choice: String): void; enum HdrType: i32 { AV_HDR_TYPE_NONE = 0, @@ -87,9 +90,9 @@ struct Location { struct MediaStream { url: String; - width: f64; - height: f64; - bitrate: f64; + width: i32; + height: i32; + bitrate: i32; } struct AVMetadata { @@ -130,15 +133,15 @@ enum PixelFormat: i32 { } struct PixelMapParams { - width: Optional; - height: Optional; + width: Optional; + height: Optional; colorFormat: Optional; } struct PlaybackStrategy { - preferredWidth: Optional; - preferredHeight: Optional; - preferredBufferDuration: Optional; + preferredWidth: Optional; + preferredHeight: Optional; + preferredBufferDuration: Optional; preferredHdr: Optional; mutedMediaType: Optional; preferredAudioLanguage: Optional; @@ -146,7 +149,7 @@ struct PlaybackStrategy { showFirstFrameOnPrepare: Optional; preferredBufferDurationForPlaying: Optional; enableSuperResolution: Optional; - thresholdForAutoQuickPlay: Optional; + thresholdForAutoQuickPlay: Optional; } interface AVMetadataExtractor { @@ -164,11 +167,15 @@ interface AVMetadataExtractor { @gen_promise("fetchMetadata") FetchMetadataSync(): Optional; + @gen_async("fetchAlbumCover") + @gen_promise("fetchAlbumCover") + FetchAlbumCoverSync(): image.PixelMap; + @gen_promise("getFrameIndexByTime") - GetFrameIndexByTimeSync(timeUs: f64): f64; + GetFrameIndexByTimeSync(timeUs: i64): i32; @gen_promise("getTimeByFrameIndex") - GetTimeByFrameIndexSync(index: f64): f64; + GetTimeByFrameIndexSync(index: i32): i64; } enum MediaDescriptionKey: String { @@ -190,12 +197,12 @@ enum MediaDescriptionKey: String { union MediaDescriptionValue { type_string: String; - type_int: f64; + type_int: i32; } union PlaybackInfoValue { type_string: String; - type_int: f64; + type_int: i32; } enum SwitchMode: i32 { @@ -207,13 +214,19 @@ enum SwitchMode: i32 { interface AVPlayer { @get GetUrl(): Optional; @set SetUrl(url: Optional): void; + @get GetAudioEffectMode(): Optional; + @set SetAudioEffectMode(audioEffectMode: Optional): void; - @get GetWidth(): f64; - @get GetHeight(): f64; + @get GetWidth(): i32; + @get GetHeight(): i32; @get GetState(): String; - @get GetDuration(): f64; - @get GetCurrentTime(): f64; + @get GetDuration(): i32; + @get GetCurrentTime(): i32; SetVolume(volume: f64): void; + @get GetAudioRendererInfo(): Optional; + @set SetAudioRendererInfo(audioRendererInfo: Optional): void; + @get GetAudioInterruptMode(): Optional; + @set SetAudioInterruptMode(audioInterruptMode: audio.InterruptMode): void; @get GetDataSrc(): Optional; @set SetDataSrc(dataSrc: Optional): void; @get GetSurfaceId(): Optional; @@ -223,12 +236,14 @@ interface AVPlayer { @get GetFdSrc(): Optional; @set SetFdSrc(fdSrc: Optional): void; SetSpeed(speed: PlaybackSpeed): void; - Seek(timeMs: f64, mode: Optional): void; + Seek(timeMs: i32, mode: Optional): void; @get GetVideoScaleType(): Optional; @set SetVideoScaleType(videoScaleType: Optional): void; IsSeekContinuousSupported() : bool; - GetPlaybackPosition(): f64; - SetBitrate(bitrate: f64): void; + GetPlaybackPosition(): i32; + SetBitrate(bitrate: i32): void; + SetDecryptionConfig(mediaKeySession: drm.MediaKeySession, secureVideoPath: bool): void; + GetMediaKeySystemInfos(): Array; @gen_async("getTrackDescription") @gen_promise("getTrackDescription") @@ -259,19 +274,19 @@ interface AVPlayer { PrepareSync(): void; @gen_promise("getSelectedTracks") - GetSelectedTracksSync(): Array; + GetSelectedTracksSync(): Array; @gen_promise("selectTrack") - SelectTrackSync(index: f64, mode: Optional): void; + SelectTrackSync(index: i32, mode: Optional): void; @gen_promise("deselectTrack") - DeselectTrackSync(index: f64): void; + DeselectTrackSync(index: i32): void; @gen_promise("setMediaSource") SetMediaSourceSync(src: MediaSource, strategy: Optional): void; @gen_promise("addSubtitleFromFd") - AddSubtitleFromFdSync(fd: f64, offset: Optional, length: Optional): void; + AddSubtitleFromFdSync(fd: i32, offset: Optional, length: Optional): void; @gen_promise("addSubtitleFromUrl") AddSubtitleFromUrlSync(url: String): void; @@ -283,10 +298,10 @@ interface AVPlayer { SetSuperResolutionSync(enabled: bool): void; @gen_promise("setVideoWindowSize") - SetVideoWindowSizeSync(width: f64, height: f64): void; + SetVideoWindowSizeSync(width: i32, height: i32): void; @gen_promise("setPlaybackRange") - SetPlaybackRangeSync(startTimeMs: f64, endTimeMs: f64, mode: Optional): void; + SetPlaybackRangeSync(startTimeMs: i32, endTimeMs: i32, mode: Optional): void; @gen_promise("setMediaMuted") SetMediaMutedSync(mediaType: MediaType, muted: bool): void; @@ -299,6 +314,8 @@ interface AVPlayer { @!sts_inject_into_class("""on(type: string, callback: object): void { if (type === "stateChange") { this.onStateChange(callback as (state: String, reason: StateChangeReason)=> void); + } else if (type === "mediaKeySystemInfoUpdate") { + this.onMediaKeySystemInfoUpdate(callback as (data: Array)=> void); } else if (type === "error") { this.onError(callback as (err: BusinessError)=> void); } else if (type === "endOfStream") { @@ -306,71 +323,80 @@ interface AVPlayer { } else if (type === "startRenderFrame") { this.onStartRenderFrame(callback as (data:undefined)=> void); } else if (type === "seekDone") { - this.onSeekDone(callback as (data: double)=> void); + this.onSeekDone(callback as (data: int)=> void); } else if (type === "durationUpdate") { - this.onDurationUpdate(callback as (data: double)=> void); + this.onDurationUpdate(callback as (data: int)=> void); } else if (type === "timeUpdate") { - this.onTimeUpdate(callback as (data: double)=> void); + this.onTimeUpdate(callback as (data: int)=> void); } else if (type === "volumeChange") { this.onVolumeChange(callback as (data: double)=> void); } else if (type === "speedDone") { - this.onSpeedDone(callback as (data: double)=> void); + this.onSpeedDone(callback as (data: int)=> void); } else if (type === "bitrateDone") { - this.onBitrateDone(callback as (data: double)=> void); + this.onBitrateDone(callback as (data: int)=> void); } else if (type === "availableBitrates") { - this.onAvailableBitrates(callback as (data: Array)=> void); + this.onAvailableBitrates(callback as (data: Array)=> void); } else if (type === "amplitudeUpdate") { this.onAmplitudeUpdate(callback as (data: Array)=> void); } else if (type === "bufferingUpdate") { - this.onBufferingUpdate(callback as (infoType: BufferingInfoType, value: double)=> void); + this.onBufferingUpdate(callback as (infoType: BufferingInfoType, value: int)=> void); } else if (type === "videoSizeChange") { - this.onVideoSizeChange(callback as (width: double, height: double)=> void); + this.onVideoSizeChange(callback as (width: int, height: int)=> void); } else if (type === "trackChange") { - this.onTrackChange(callback as (index: double, isSelected: boolean)=> void); + this.onTrackChange(callback as (index: int, isSelected: boolean)=> void); } else if (type === "subtitleUpdate") { this.onSubtitleUpdate(callback as (data: SubtitleInfo)=> void); } else if (type === "superResolutionChanged") { this.onSuperResolutionChanged(callback as (enabled: boolean)=> void); } else if (type === "trackInfoUpdate") { - this.onTrackInfoUpdate(callback as (data: Array>)=> void); + this.onTrackInfoUpdate(callback as (data: Array>)=> void); + } else if (type === "audioInterrupt"){ + this.onAudioInterrupt(callback as (interruptEvent: audio.InterruptEvent)=> void); + } else if (type === "audioOutputDeviceChangeWithInfo"){ + this.onAudioOutputDeviceChangeWithInfo(callback as (audioStreamDeviceChangeInfo: audio.AudioStreamDeviceChangeInfo)=> void); } else { throw new Error(`Unknown type: ${type}`); } }""") OnError(callback: (err: @sts_type("BusinessError") Opaque )=> void): void; + OnMediaKeySystemInfoUpdate(callback: (data: Array)=> void): void; OnStateChange(callback: (state: String, reason: StateChangeReason)=> void): void; OnEndOfStream(callback: (data: @sts_type("undefined") Opaque) => void): void; OnStartRenderFrame(callback: (data: @sts_type("undefined") Opaque) => void): void; - OnSeekDone(callback: (data: f64) => void): void; - OnDurationUpdate(callback: (data: f64) => void): void; - OnTimeUpdate(callback: (data: f64) => void): void; + OnSeekDone(callback: (data: i32) => void): void; + OnDurationUpdate(callback: (data: i32) => void): void; + OnTimeUpdate(callback: (data: i32) => void): void; OnVolumeChange(callback: (data: f64) => void): void; - OnSpeedDone(callback: (data: f64) => void): void; - OnBitrateDone(callback: (data: f64) => void): void; - OnAvailableBitrates(callback: (data: Array) => void): void; + OnSpeedDone(callback: (data: i32) => void): void; + OnBitrateDone(callback: (data: i32) => void): void; + OnAvailableBitrates(callback: (data: Array) => void): void; OnAmplitudeUpdate(callback: (data: Array) => void): void; - OnBufferingUpdate(callback: (infoType: BufferingInfoType, value: f64) => void): void; - OnVideoSizeChange(callback: (width: f64, height: f64) => void): void; - OnTrackChange(callback: (index: f64, isSelected: bool) => void): void; + OnBufferingUpdate(callback: (infoType: BufferingInfoType, value: i32) => void): void; + OnVideoSizeChange(callback: (width: i32, height: i32) => void): void; + OnTrackChange(callback: (index: i32, isSelected: bool) => void): void; OnSubtitleUpdate(callback: (data: SubtitleInfo) => void): void; OnSuperResolutionChanged(callback: (enabled: bool) => void): void; OnTrackInfoUpdate(callback: (data: Array<@record Map>) => void): void; + OnAudioInterrupt(callback: (data: audio.InterruptEvent) => void): void; + OnAudioOutputDeviceChangeWithInfo(callback: (data: audio.AudioStreamDeviceChangeInfo) => void): void; - @!sts_inject_into_interface("on(type: string, payloadTypes: Array, callback: (messages: Array, playbackPosition?: double)=> void): void;") - @!sts_inject_into_class("""on(type: string, payloadTypes: Array, callback: object): void { + @!sts_inject_into_interface("on(type: string, payloadTypes: Array, callback: (messages: Array, playbackPosition?: int)=> void): void;") + @!sts_inject_into_class("""on(type: string, payloadTypes: Array, callback: object): void { if (type === "seiMessageReceived") { - this.onSeiMessageReceived(payloadTypes as (Array), callback as (messages: Array, playbackPosition?: double) => void); + this.onSeiMessageReceived(payloadTypes as (Array), callback as (messages: Array, playbackPosition?: int) => void); } else { } }""") - OnSeiMessageReceived(payloadTypes: Array, callback: (messages: Array, - playbackPosition: Optional) => void): void; + OnSeiMessageReceived(payloadTypes: Array, callback: (messages: Array, + playbackPosition: Optional) => void): void; @!sts_inject_into_interface("off(type: string, callback?: (state: string, reason: StateChangeReason)=> void): void;") @!sts_inject_into_interface("off(type: string, callback?: (data: object)=> void): void;") @!sts_inject_into_class("""off(type: string, callback?: object): void { if (type === "error") { this.offError(callback as (((err: BusinessError)=> void) | undefined)); + } else if (type === "mediaKeySystemInfoUpdate") { + this.offMediaKeySystemInfoUpdate(callback as (((data: Array)=> void) | undefined)); } else if (type === "stateChange") { this.offStateChange(callback as (((state: String, reason: StateChangeReason)=> void)) | undefined); } else if (type === "endOfStream") { @@ -378,69 +404,76 @@ interface AVPlayer { } else if (type === "startRenderFrame") { this.offStartRenderFrame(callback as (((data:undefined)=> void) | undefined)); } else if (type === "seekDone") { - this.offSeekDone(callback as (((data: double) => void) | undefined)); + this.offSeekDone(callback as (((data: int) => void) | undefined)); } else if (type === "durationUpdate") { - this.offDurationUpdate(callback as (((data: double) => void) | undefined)); + this.offDurationUpdate(callback as (((data: int) => void) | undefined)); } else if (type === "timeUpdate") { - this.offTimeUpdate(callback as (((data: double) => void) | undefined)); + this.offTimeUpdate(callback as (((data: int) => void) | undefined)); } else if (type === "volumeChange") { this.offVolumeChange(callback as (((data: double) => void) | undefined)); } else if (type === "speedDone") { - this.offSpeedDone(callback as (((data: double) => void) | undefined)); + this.offSpeedDone(callback as (((data: int) => void) | undefined)); } else if (type === "bitrateDone") { - this.offBitrateDone(callback as (((data: double) => void) | undefined)); + this.offBitrateDone(callback as (((data: int) => void) | undefined)); } else if (type === "availableBitrates") { - this.offAvailableBitrates(callback as (((data: Array) => void) | undefined)); + this.offAvailableBitrates(callback as (((data: Array) => void) | undefined)); } else if (type === "amplitudeUpdate") { this.offAmplitudeUpdate(callback as (((data: Array) => void) | undefined)); } else if (type === "bufferingUpdate") { - this.offBufferingUpdate(callback as (((infoType: object, value: double) => void) | undefined)); + this.offBufferingUpdate(callback as (((infoType: object, value: int) => void) | undefined)); } else if (type === "videoSizeChange") { - this.offVideoSizeChange(callback as (((width: double, height: double) => void) | undefined)); + this.offVideoSizeChange(callback as (((width: int, height: int) => void) | undefined)); } else if (type === "trackChange") { - this.offTrackChange(callback as (((index: double, isSelected: boolean) => void) | undefined)); + this.offTrackChange(callback as (((index: int, isSelected: boolean) => void) | undefined)); } else if (type === "subtitleUpdate") { this.offSubtitleUpdate(callback as (((data: object) => void) | undefined)); } else if (type === "superResolutionChanged") { this.offSuperResolutionChanged(callback as (((enabled: boolean) => void) | undefined)); } else if (type === "trackInfoUpdate") { - this.offTrackInfoUpdate(callback as (((data: Array>) => void) | undefined)); + this.offTrackInfoUpdate(callback as (((data: Array>) => void) | undefined)); + } else if (type === "audioInterrupt"){ + this.offAudioInterrupt(callback as (((interruptEvent: audio.InterruptEvent)=> void) | undefined)); + } else if (type === "audioOutputDeviceChangeWithInfo"){ + this.offAudioOutputDeviceChangeWithInfo(callback as (((audioStreamDeviceChangeInfo: audio.AudioStreamDeviceChangeInfo)=> void) | undefined)); } else { throw new Error(`Unknown type: ${type}`); } }""") OffError(callback: Optional<(err: @sts_type("BusinessError") Opaque)=> void>): void; + OffMediaKeySystemInfoUpdate(callback: Optional<(data: Array)=> void>): void; OffStateChange(callback: Optional<(state: String, reason: StateChangeReason)=> void>): void; OffEndOfStream(callback: Optional<(data: @sts_type("undefined") Opaque) => void>): void; OffStartRenderFrame(callback: Optional<(data: @sts_type("undefined") Opaque) => void>): void; - OffSeekDone(callback: Optional<(data: f64) => void>): void; - OffDurationUpdate(callback: Optional<(data: f64) => void>): void; - OffTimeUpdate(callback: Optional<(data: f64) => void>): void; + OffSeekDone(callback: Optional<(data: i32) => void>): void; + OffDurationUpdate(callback: Optional<(data: i32) => void>): void; + OffTimeUpdate(callback: Optional<(data: i32) => void>): void; OffVolumeChange(callback: Optional<(data: f64) => void>): void; - OffSpeedDone(callback: Optional<(data: f64) => void>): void; - OffBitrateDone(callback: Optional<(data: f64) => void>): void; - OffAvailableBitrates(callback: Optional<(data: Array) => void>): void; + OffSpeedDone(callback: Optional<(data: i32) => void>): void; + OffBitrateDone(callback: Optional<(data: i32) => void>): void; + OffAvailableBitrates(callback: Optional<(data: Array) => void>): void; OffAmplitudeUpdate(callback: Optional<(data: Array) => void>): void; - OffBufferingUpdate(callback: Optional<(infoType: BufferingInfoType, value: f64) => void>): void; - OffVideoSizeChange(callback: Optional<(width: f64, height: f64) => void>): void; - OffTrackChange(callback: Optional<(index: f64, isSelected: bool) => void>): void; + OffBufferingUpdate(callback: Optional<(infoType: BufferingInfoType, value: i32) => void>): void; + OffVideoSizeChange(callback: Optional<(width: i32, height: i32) => void>): void; + OffTrackChange(callback: Optional<(index: i32, isSelected: bool) => void>): void; OffSubtitleUpdate(callback: Optional<(data: SubtitleInfo) => void>): void; OffSuperResolutionChanged(callback: Optional<(enabled: bool) => void>): void; - OffTrackInfoUpdate(callback: Optional<(data: Array<@record Map>) => void>): void; + OffTrackInfoUpdate(callback: Optional<(data: Array<@record Map>) => void>): void; + OffAudioInterrupt(callback: Optional<(data: audio.InterruptEvent) => void>): void; + OffAudioOutputDeviceChangeWithInfo(callback: Optional<(data: audio.AudioStreamDeviceChangeInfo) => void>): void; - @!sts_inject_into_interface("off(type: string, payloadTypes: Array, callback?: (messages: Array, playbackPosition?: double)=> void): void;") - @!sts_inject_into_class("""off(type: string, payloadTypes: Array, callback?: object): void { + @!sts_inject_into_interface("off(type: string, payloadTypes: Array, callback?: (messages: Array, playbackPosition?: int)=> void): void;") + @!sts_inject_into_class("""off(type: string, payloadTypes: Array, callback?: object): void { if (type === "seiMessageReceived") { - this.offSeiMessageReceived(payloadTypes as (Array), callback as (((messages: Array, playbackPosition?: double) => void) | undefined)); + this.offSeiMessageReceived(payloadTypes as (Array), callback as (((messages: Array, playbackPosition?: int) => void) | undefined)); } else { } }""") - OffSeiMessageReceived(payloadTypes: Array, callback: Optional<(messages: Array, - playbackPosition: Optional) => void>): void; + OffSeiMessageReceived(payloadTypes: Array, callback: Optional<(messages: Array, + playbackPosition: Optional) => void>): void; } struct SeiMessage { - payloadType: f64; + payloadType: i32; payload: @arraybuffer Array; } @@ -467,8 +500,8 @@ enum StateChangeReason: i32 { } struct SubtitleInfo { - duration: Optional; - startTime: Optional; + duration: Optional; + startTime: Optional; text: Optional; } @@ -585,16 +618,16 @@ enum PlaybackInfoKey: String { } struct VideoRecorderProfile { - @readonly audioBitrate: f64; - @readonly audioChannels: f64; + @readonly audioBitrate: i32; + @readonly audioChannels: i32; @readonly audioCodec: CodecMimeType; - @readonly audioSampleRate: f64; + @readonly audioSampleRate: i32; @readonly fileFormat: ContainerFormatType; - @readonly videoBitrate: f64; + @readonly videoBitrate: i32; @readonly videoCodec: CodecMimeType; - @readonly videoFrameWidth: f64; - @readonly videoFrameHeight: f64; - @readonly videoFrameRate: f64; + @readonly videoFrameWidth: i32; + @readonly videoFrameHeight: i32; + @readonly videoFrameRate: i32; } struct VideoRecorderConfig { @@ -602,19 +635,23 @@ struct VideoRecorderConfig { videoSourceType: VideoSourceType; profile: VideoRecorderProfile; url: String; - rotation: Optional; + rotation: Optional; location: Optional; } struct WatermarkConfig { - top: f64; - left: f64; + top: i32; + left: i32; } interface AVImageGenerator { @get GetFdSrc(): Optional; @set SetFdSrc(fdSrc: Optional): void; + @gen_async("fetchFrameByTime") + @gen_promise("fetchFrameByTime") + FetchFrameByTimeSync(timeUs: i64, options: AVImageQueryOptions, param: PixelMapParams): image.PixelMap; + @gen_async("release") @gen_promise("release") ReleaseSync(): void; @@ -665,12 +702,19 @@ interface AVRecorder { @gen_promise("isWatermarkSupported") IsWatermarkSupportedSync(): bool; + @gen_promise("setWatermark") + SetWatermarkSync(watermark: image.PixelMap, config: WatermarkConfig): void; + @gen_promise("updateRotation") - UpdateRotationSync(rotation: f64): void; + UpdateRotationSync(rotation: i32): void; @gen_async("getAudioCapturerMaxAmplitude") @gen_promise("getAudioCapturerMaxAmplitude") - GetAudioCapturerMaxAmplitudeSync(): f64; + GetAudioCapturerMaxAmplitudeSync(): i32; + + @gen_async("getCurrentAudioCapturerInfo") + @gen_promise("getCurrentAudioCapturerInfo") + GetCurrentAudioCapturerInfoSync(): Optional; @gen_async("getAvailableEncoder") @gen_promise("getAvailableEncoder") @@ -683,6 +727,8 @@ interface AVRecorder { this.onStateChange(callback as (state: String, reason: StateChangeReason)=> void); } else if (type === "error") { this.onError(callback as (err: BusinessError)=> void); + } else if (type === "audioCapturerChange") { + this.onAudioCapturerChange(callback as (audioCapturerChangeInfo: audio.AudioCapturerChangeInfo)=> void); } else if (type === "photoAssetAvailable") { this.onPhotoAssetAvailable(callback as (photoAsset: photoAccessHelper.PhotoAsset)=> void); } else { @@ -691,6 +737,7 @@ interface AVRecorder { }""") OnError(callback: (err: @sts_type("BusinessError") Opaque )=> void): void; OnStateChange(callback: (state: String, reason: StateChangeReason)=> void): void; + OnAudioCapturerChange(callback: (data: audio.AudioCapturerChangeInfo) => void): void; OnPhotoAssetAvailable(callback: (data: @sts_type("photoAccessHelper.PhotoAsset") Opaque) => void): void; @!sts_inject_into_interface("off(type: string, callback?: (state: string, reason: StateChangeReason)=> void): void;") @@ -700,6 +747,8 @@ interface AVRecorder { this.offError(callback as (((err: BusinessError)=> void) | undefined)); } else if (type === "stateChange") { this.offStateChange(callback as (((state: String, reason: StateChangeReason)=> void)) | undefined); + } else if (type === "audioCapturerChange"){ + this.offAudioCapturerChange(callback as (((audioCapturerChangeInfo: audio.AudioCapturerChangeInfo)=> void)) | undefined); } else if (type === "photoAssetAvailable") { this.offPhotoAssetAvailable(callback as (((photoAsset: photoAccessHelper.PhotoAsset)=> void)) | undefined); } else { @@ -708,6 +757,7 @@ interface AVRecorder { }""") OffError(callback: Optional<(err: @sts_type("BusinessError") Opaque)=> void>): void; OffStateChange(callback: Optional<(state: String, reason: StateChangeReason)=> void>): void; + OffAudioCapturerChange(callback: Optional<(data: audio.AudioCapturerChangeInfo) => void>): void; OffPhotoAssetAvailable(callback: Optional<(data: @sts_type("photoAccessHelper.PhotoAsset") Opaque) => void>): void; } @@ -731,8 +781,8 @@ enum MediaType: i32 { } struct Range { - min: f64; - max: f64; + min: i32; + max: i32; } struct EncoderInfo { @@ -743,7 +793,7 @@ struct EncoderInfo { width: Optional; height: Optional; channels: Optional; - sampleRate: Optional>; + sampleRate: Optional>; } enum BufferingInfoType: i32 { @@ -757,8 +807,8 @@ interface AVTranscoder { @get GetFdSrc(): AVFileDescriptor; @set SetFdSrc(fdSrc: AVFileDescriptor): void; - @get GetFdDst(): f64; - @set SetFdDst(fdDst: f64): void; + @get GetFdDst(): i32; + @set SetFdDst(fdDst: i32): void; @gen_async("prepare") @gen_promise("prepare") @@ -791,7 +841,7 @@ interface AVTranscoder { } else if (type === "error") { this.onError(callback as (err: BusinessError)=> void); } else if (type === "progressUpdate") { - this.onProgressUpdate(callback as (data: double)=> void); + this.onProgressUpdate(callback as (data: int)=> void); } else { throw new Error(`Unknown type: ${type}`); } @@ -804,7 +854,7 @@ interface AVTranscoder { } else if (type === "error") { this.offError(callback as (((err: BusinessError)=> void) | undefined )); } else if (type === "progressUpdate") { - this.offProgressUpdate(callback as (((data: double)=> void) | undefined )); + this.offProgressUpdate(callback as (((data: int)=> void) | undefined )); } else { throw new Error(`Unknown type: ${type}`); } @@ -816,18 +866,18 @@ interface AVTranscoder { OnError(callback: (err: @sts_type("BusinessError") Opaque)=> void): void; OffError(callback: Optional<(err: @sts_type("BusinessError") Opaque)=> void>): void; - OnProgressUpdate(callback: (data: f64) => void): void; - OffProgressUpdate(callback: Optional<(data: f64) => void>); + OnProgressUpdate(callback: (data: i32) => void): void; + OffProgressUpdate(callback: Optional<(data: i32) => void>); } struct AVTranscoderConfig { - audioBitrate: Optional; + audioBitrate: Optional; audioCodec: Optional; fileFormat: ContainerFormatType; - videoBitrate: Optional; + videoBitrate: Optional; videoCodec: Optional; - videoFrameWidth: Optional; - videoFrameHeight: Optional; + videoFrameWidth: Optional; + videoFrameHeight: Optional; } enum AVScreenCaptureRecordPreset:i32 { @@ -841,15 +891,15 @@ enum AVScreenCaptureFillMode:i32 { } struct AVScreenCaptureRecordConfig { - fd: f64; - frameWidth: Optional; - frameHeight: Optional; - videoBitrate: Optional; - audioSampleRate: Optional; - audioChannelCount: Optional; - audioBitrate: Optional; + fd: i32; + frameWidth: Optional; + frameHeight: Optional; + videoBitrate: Optional; + audioSampleRate: Optional; + audioChannelCount: Optional; + audioBitrate: Optional; preset: Optional; - displayId: Optional; + displayId: Optional; fillMode: Optional; } @@ -870,20 +920,20 @@ struct AVRecorderConfig { metaSourceTypes: Optional>; fileGenerationMode: Optional; metadata: Optional; - maxDuration: Optional; + maxDuration: Optional; } struct AVRecorderProfile { - audioBitrate: Optional; - audioChannels: Optional; + audioBitrate: Optional; + audioChannels: Optional; audioCodec: Optional; - audioSampleRate: Optional; + audioSampleRate: Optional; fileFormat: ContainerFormatType; - videoBitrate: Optional; + videoBitrate: Optional; videoCodec: Optional; - videoFrameWidth: Optional; - videoFrameHeight: Optional; - videoFrameRate: Optional; + videoFrameWidth: Optional; + videoFrameHeight: Optional; + videoFrameRate: Optional; isHdr: Optional; enableTemporalScale: Optional; enableStableQualityMode: Optional; @@ -942,7 +992,7 @@ interface AVScreenCaptureRecorder { StopRecordingSync(): void; @gen_promise("skipPrivacyMode") - SkipPrivacyModeSync(windowIDs: Array): void; + SkipPrivacyModeSync(windowIDs: Array): void; @gen_promise("setMicEnabled") SetMicEnabledSync(enable: bool): void; @@ -997,15 +1047,15 @@ interface MediaSourceLoadingRequest { @get GetUrl(): String; @get GetHeader(): Optional<@record Map>; - RespondData(uuid: f64, offset: f64, buffer: @arraybuffer Array): Optional; - RespondHeader(uuid: f64, header: Optional<@record Map>, redirectUrl: Optional): void; - FinishLoading(uuid: f64, state: LoadingRequestError): void; + RespondData(uuid: i64, offset: i64, buffer: @arraybuffer Array): Optional; + RespondHeader(uuid: i64, header: Optional<@record Map>, redirectUrl: Optional): void; + FinishLoading(uuid: i64, state: LoadingRequestError): void; } struct MediaSourceLoader { - open: (request: MediaSourceLoadingRequest) => f64; - read: (uuid: f64, requestedOffset: f64, requestedLength: f64) => void; - close: (uuid: f64) => void; + open: (request: MediaSourceLoadingRequest) => i64; + read: (uuid: i64, requestedOffset: i64, requestedLength: i64) => void; + close: (uuid: i64) => void; } interface MediaSource { diff --git a/frameworks/taihe/idl/soundPool.taihe b/frameworks/taihe/idl/soundPool.taihe index ffd9ec191..6c96a10a1 100644 --- a/frameworks/taihe/idl/soundPool.taihe +++ b/frameworks/taihe/idl/soundPool.taihe @@ -19,52 +19,58 @@ import { BusinessError, ErrorCallback, AsyncCallback, Callback } from '@ohos.base'; """) +use ohos.multimedia.audio as audio; + struct PlayParameters { - loop: Optional; - rate: Optional; + loop: Optional; + rate: Optional; leftVolume: Optional; rightVolume: Optional; - priority: Optional; + priority: Optional; parallelPlayFlag: Optional; } interface SoundPool { @gen_async("load") @gen_promise("load") - LoadSync(uri: String): f64; + LoadSync(uri: String): i32; @gen_async("load") @gen_promise("load") - LoadWithFdSync(fd: f64, offset: f64, length: f64): f64; + LoadWithFdSync(fd: i32, offset: f64, length: f64): i32; @gen_promise("play") - PlaySync(soundID: f64, params: Optional): f64; + PlaySync(soundID: i32, params: Optional): i32; @gen_async("play") - PlayWithoutParam(soundID: f64): f64; + PlayWithoutParam(soundID: i32): i32; @gen_async("play") - PlayWithParam(soundID: f64, params: PlayParameters): f64; + PlayWithParam(soundID: i32, params: PlayParameters): i32; @gen_async("stop") @gen_promise("stop") - StopSync(streamID: f64): void; + StopSync(streamID: i32): void; @gen_async("setLoop") @gen_promise("setLoop") - SetLoopSync(streamID: f64, loop: f64): void; + SetLoopSync(streamID: i32, loop: i32): void; + + @gen_async("setRate") + @gen_promise("setRate") + SetRateSync(streamID: i32, rate: audio.AudioRendererRate): void; @gen_async("setPriority") @gen_promise("setPriority") - SetPrioritySync(streamID: f64, priority: f64): void; + SetPrioritySync(streamID: i32, priority: i32): void; @gen_async("setVolume") @gen_promise("setVolume") - SetVolumeSync(streamID: f64, leftVolume: f64, rightVolume: f64): void; + SetVolumeSync(streamID: i32, leftVolume: f64, rightVolume: f64): void; @gen_async("unload") @gen_promise("unload") - UnloadSync(soundID: f64): void; + UnloadSync(soundID: i32): void; @gen_async("release") @gen_promise("release") @@ -73,11 +79,11 @@ interface SoundPool { @!sts_inject_into_interface("on(type: string, callback: (data: object)=> void): void;") @!sts_inject_into_class("""on(type: string, callback: object): void { if (type === "playFinishedWithStreamId") { - this.onPlayFinishedWithStreamId(callback as (data: double)=> void); + this.onPlayFinishedWithStreamId(callback as (data: int)=> void); } else if (type === "error") { this.onError(callback as (err: BusinessError)=> void); } else if (type === "loadComplete") { - this.onLoadComplete(callback as (data: double)=> void); + this.onLoadComplete(callback as (data: int)=> void); } else if (type === "playFinished") { this.onPlayFinished(callback as (data: undefined)=> void); } else { @@ -103,10 +109,10 @@ interface SoundPool { OnError(callback: (err: @sts_type("BusinessError") Opaque)=> void): void; OffError(): void; - OnPlayFinishedWithStreamId(callback: (data: f64) => void): void; + OnPlayFinishedWithStreamId(callback: (data: i32) => void): void; OffPlayFinishedWithStreamId(); - OnLoadComplete(callback: (data: f64) => void): void; + OnLoadComplete(callback: (data: i32) => void): void; OffLoadComplete(); OnPlayFinished(callback: (data: @sts_type("undefined") Opaque) => void): void; diff --git a/frameworks/taihe/idl/systemTonePlayer.taihe b/frameworks/taihe/idl/systemTonePlayer.taihe index 32a891dbb..98ba210be 100644 --- a/frameworks/taihe/idl/systemTonePlayer.taihe +++ b/frameworks/taihe/idl/systemTonePlayer.taihe @@ -15,6 +15,10 @@ @!namespace("multimedia.systemTonePlayer") +@!sts_inject(""" +import { BusinessError } from '@ohos.base'; +""") + @!sts_inject(""" { loadLibrary("system_sound_manager_taihe.z"); } """) diff --git a/frameworks/taihe/media/include/avimagegenerator_taihe.h b/frameworks/taihe/media/include/avimagegenerator_taihe.h index b702ba0b5..a016e65c0 100644 --- a/frameworks/taihe/media/include/avimagegenerator_taihe.h +++ b/frameworks/taihe/media/include/avimagegenerator_taihe.h @@ -33,11 +33,17 @@ public: AVImageGeneratorImpl(std::shared_ptr avMetadataHelper); optional GetFdSrc(); void SetFdSrc(optional_view fdSrc); + ::ohos::multimedia::image::image::PixelMap FetchFrameByTimeSync(int64_t timeUs, + ::ohos::multimedia::media::AVImageQueryOptions options, ::ohos::multimedia::media::PixelMapParams const& param); void ReleaseSync(); private: std::shared_ptr helper_; struct OHOS::Media::AVFileDescriptor fileDescriptor_; OHOS::Media::HelperState state_ { OHOS::Media::HelperState::HELPER_STATE_IDLE }; + std::shared_ptr pixel_ = nullptr; + int64_t timeUs_ = 0; + int32_t option_ = 0; + OHOS::Media::PixelMapParams param_; }; } // namespace ANI::Media #endif // AVIMAGEGENERATOR_TAIHE_H \ No newline at end of file diff --git a/frameworks/taihe/media/include/avmetadataextractor_taihe.h b/frameworks/taihe/media/include/avmetadataextractor_taihe.h index e14a333dd..e9829db5c 100644 --- a/frameworks/taihe/media/include/avmetadataextractor_taihe.h +++ b/frameworks/taihe/media/include/avmetadataextractor_taihe.h @@ -37,9 +37,10 @@ public: optional GetDataSrc(); void SetDataSrc(optional_view dataSrc); optional FetchMetadataSync(); + ohos::multimedia::image::image::PixelMap FetchAlbumCoverSync(); void ReleaseSync(); - double GetFrameIndexByTimeSync(double timeUs); - double GetTimeByFrameIndexSync(double index); + int32_t GetFrameIndexByTimeSync(double timeUs); + double GetTimeByFrameIndexSync(int32_t index); private: std::shared_ptr helper_; std::shared_ptr dataSrcCb_ = nullptr; diff --git a/frameworks/taihe/media/include/avplayer_callback_taihe.h b/frameworks/taihe/media/include/avplayer_callback_taihe.h index 36b39bd7c..e45f9aa5b 100644 --- a/frameworks/taihe/media/include/avplayer_callback_taihe.h +++ b/frameworks/taihe/media/include/avplayer_callback_taihe.h @@ -71,6 +71,8 @@ public: void OnMaxAmplitudeCollectedCb(const int32_t extra, const Format &infoBody); void OnTrackInfoUpdate(const int32_t extra, const Format &infoBody); void OnTrackChangedCb(const int32_t extra, const Format &infoBody); + void OnAudioInterruptCb(const int32_t extra, const Format &infoBody); + void OnAudioDeviceChangeCb(const int32_t extra, const Format &infoBody); void OnDrmInfoUpdatedCb(const int32_t extra, const Format &infoBody); void OnSuperResolutionChangedCb(const int32_t extra, const Format &infoBody); void OnSeiInfoCb(const int32_t extra, const Format &infoBody); diff --git a/frameworks/taihe/media/include/avplayer_taihe.h b/frameworks/taihe/media/include/avplayer_taihe.h index 73bbf8b2b..b1092ee47 100644 --- a/frameworks/taihe/media/include/avplayer_taihe.h +++ b/frameworks/taihe/media/include/avplayer_taihe.h @@ -30,6 +30,7 @@ namespace ANI::Media { using namespace taihe; using namespace ohos::multimedia::media; +using namespace ohos::multimedia::drm; using TaskRet = std::pair; using StateChangeCallback = void(string_view, ohos::multimedia::media::StateChangeReason); @@ -106,15 +107,21 @@ namespace AVPlayerEvent { class AVPlayerImpl : public AVPlayerNotify { public: AVPlayerImpl(); - + optional GetUrl(); void SetUrl(optional_view url); - double GetWidth(); - double GetHeight(); + optional GetAudioEffectMode(); + void SetAudioEffectMode(optional_view audioEffectMode); + int32_t GetWidth(); + int32_t GetHeight(); string GetState(); - double GetDuration(); - double GetCurrentTime(); + int32_t GetDuration(); + int32_t GetCurrentTime(); void SetVolume(double volume); + optional GetAudioRendererInfo(); + void SetAudioRendererInfo(optional_view audioRendererInfo); + optional<::ohos::multimedia::audio::InterruptMode> GetAudioInterruptMode(); + void SetAudioInterruptMode(::ohos::multimedia::audio::InterruptMode audioInterruptMode); optional GetDataSrc(); void SetDataSrc(optional_view dataSrc); optional GetSurfaceId(); @@ -124,81 +131,89 @@ public: optional GetFdSrc(); void SetFdSrc(optional_view fdSrc); void SetSpeed(PlaybackSpeed speed); - void Seek(double timeMs, optional_view mode); + void Seek(int32_t timeMs, optional_view mode); optional GetVideoScaleType(); void SetVideoScaleType(optional_view videoScaleType); bool IsSeekContinuousSupported(); array> GetTrackDescriptionSync(); - double GetPlaybackPosition(); - void SetBitrate(double bitrate); + int32_t GetPlaybackPosition(); + void SetBitrate(int32_t bitrate); + void SetDecryptionConfig(ohos::multimedia::drm::weak::MediaKeySession mediaKeySession, bool secureVideoPath); + ::taihe::array GetMediaKeySystemInfos(); void StopSync(); void PlaySync(); void ResetSync(); void ReleaseSync(); void PauseSync(); void PrepareSync(); - void SetMediaSourceSync(weak::MediaSource src, optional_view strategy); + void SetMediaSourceSync(ohos::multimedia::media::weak::MediaSource src, optional_view strategy); void GetDefaultStrategy(AVPlayStrategyTmp &strategy); void GetPlayStrategy(AVPlayStrategyTmp &playStrategy, PlaybackStrategy strategy); void EnqueueMediaSourceTask(const std::shared_ptr &mediaSource, const struct AVPlayStrategy &strategy); - void AddSubtitleFromFdSync(double fd, optional_view offset, optional_view length); - array GetSelectedTracksSync(); - void SelectTrackSync(double index, ::taihe::optional_view<::ohos::multimedia::media::SwitchMode> mode); - void DeselectTrackSync(double index); + void AddSubtitleFromFdSync(int32_t fd, optional_view offset, optional_view length); + array GetSelectedTracksSync(); + void SelectTrackSync(int32_t index, ::taihe::optional_view<::ohos::multimedia::media::SwitchMode> mode); + void DeselectTrackSync(int32_t index); void AddSubtitleFromUrlSync(::taihe::string_view url); map GetPlaybackInfoSync(); - void SetVideoWindowSizeSync(double width, double height); + void SetVideoWindowSizeSync(int32_t width, int32_t height); void SetSuperResolutionSync(bool enabled); - void SetPlaybackRangeSync(double startTimeMs, double endTimeMs, + void SetPlaybackRangeSync(int32_t startTimeMs, int32_t endTimeMs, optional_view<::ohos::multimedia::media::SeekMode> mode); void SetMediaMutedSync(::ohos::multimedia::media::MediaType mediaType, bool muted); void SetPlaybackStrategySync(::ohos::multimedia::media::PlaybackStrategy const& strategy); void OnError(callback_view callback); void OnStateChange(callback_view callback); - void OnMediaKeySystemInfoUpdate(callback_view callback); + void OnMediaKeySystemInfoUpdate(callback_view data)> callback); void OnEndOfStream(callback_view callback); void OnStartRenderFrame(callback_view callback); - void OnSeekDone(callback_view callback); - void OnDurationUpdate(callback_view callback); - void OnTimeUpdate(callback_view callback); + void OnSeekDone(callback_view callback); + void OnDurationUpdate(callback_view callback); + void OnTimeUpdate(callback_view callback); void OnVolumeChange(callback_view callback); - void OnSpeedDone(callback_view callback); - void OnBitrateDone(callback_view callback); - void OnAvailableBitrates(callback_view)> callback); + void OnSpeedDone(callback_view callback); + void OnBitrateDone(callback_view callback); + void OnAvailableBitrates(callback_view)> callback); void OnAmplitudeUpdate(callback_view)> callback); - void OnBufferingUpdate(callback_view callback); - void OnVideoSizeChange(callback_view callback); - void OnTrackChange(callback_view callback); + void OnBufferingUpdate(callback_view callback); + void OnVideoSizeChange(callback_view callback); + void OnTrackChange(callback_view callback); void OnSubtitleUpdate(callback_view callback); void OnSuperResolutionChanged(callback_view callback); void OnTrackInfoUpdate(callback_view>)> callback); - void OnSeiMessageReceived(array_view payloadTypes, - callback_view, optional_view)> callback); + void OnSeiMessageReceived(array_view payloadTypes, + callback_view, optional_view)> callback); + void OnAudioInterrupt(callback_view callback); + void OnAudioOutputDeviceChangeWithInfo(callback_view callback); void OffError(optional_view> callback); void OffStateChange(optional_view> callback); - void OffMediaKeySystemInfoUpdate(optional_view> callback); + void OffMediaKeySystemInfoUpdate(optional_view data)>> callback); void OffEndOfStream(optional_view> callback); void OffStartRenderFrame(optional_view> callback); - void OffSeekDone(optional_view> callback); - void OffDurationUpdate(optional_view> callback); - void OffTimeUpdate(optional_view> callback); + void OffSeekDone(optional_view> callback); + void OffDurationUpdate(optional_view> callback); + void OffTimeUpdate(optional_view> callback); void OffVolumeChange(optional_view> callback); - void OffSpeedDone(optional_view> callback); - void OffBitrateDone(optional_view> callback); - void OffAvailableBitrates(optional_view)>> callback); + void OffSpeedDone(optional_view> callback); + void OffBitrateDone(optional_view> callback); + void OffAvailableBitrates(optional_view)>> callback); void OffAmplitudeUpdate(optional_view)>> callback); void OffBufferingUpdate(optional_view> callback); - void OffVideoSizeChange(optional_view> callback); - void OffTrackChange(optional_view> callback); + int32_t)>> callback); + void OffVideoSizeChange(optional_view> callback); + void OffTrackChange(optional_view> callback); void OffSubtitleUpdate(optional_view> callback); void OffSuperResolutionChanged(optional_view> callback); - void OffTrackInfoUpdate(optional_view>)>> callback); - void OffSeiMessageReceived(array_view payloadTypes, - optional_view, optional_view)>> callback); + void OffTrackInfoUpdate(optional_view>)>> callback); + void OffSeiMessageReceived(array_view payloadTypes, + optional_view, optional_view)>> callback); + void OffAudioInterrupt(optional_view> callback); + void OffAudioOutputDeviceChangeWithInfo(optional_view> callback); bool GetIntArrayArgument(std::vector &vec, const std::vector &inputArray); void SeiMessageCallbackOff(std::string &callbackName, const std::vector &payloadTypes); void MaxAmplitudeCallbackOff(std::string callbackName); @@ -228,9 +243,11 @@ private: std::shared_ptr> ResetTask(); std::shared_ptr> ReleaseTask(); static void SeekEnqueueTask(AVPlayerImpl *jsPlayer, int32_t time, int32_t mode); - static std::shared_ptr GetAVMediaSource(weak::MediaSource src, + static std::shared_ptr GetAVMediaSource(ohos::multimedia::media::weak::MediaSource src, std::shared_ptr &srcTmp); static PlayerSeekMode TransferSeekMode(int32_t mode); + bool HandleParameter(ohos::multimedia::audio::AudioRendererInfo src, + OHOS::AudioStandard::AudioRendererInfo &audioRendererInfo); void AddSubSource(std::string url); void SetSurface(const std::string &surfaceStr); void StartListenCurrentResource(); @@ -276,6 +293,7 @@ private: std::multimap> localDrmInfos_; std::shared_ptr dataSrcCb_ = nullptr; struct DataSrcDescriptor dataSrcDescriptor_; + int32_t audioEffectMode_ = OHOS::AudioStandard::AudioEffectMode::EFFECT_DEFAULT; std::unique_ptr taskQue_; bool loop_ = false; std::string surface_ = ""; @@ -285,6 +303,7 @@ private: OHOS::AudioStandard::StreamUsage::STREAM_USAGE_MEDIA, 0 }; + OHOS::AudioStandard::InterruptMode interruptMode_ = OHOS::AudioStandard::InterruptMode::SHARE_MODE; Format playbackInfo_; int32_t index_ = -1; int32_t mode_ = SWITCH_SMOOTH; diff --git a/frameworks/taihe/media/include/avrecorder_callback_taihe.h b/frameworks/taihe/media/include/avrecorder_callback_taihe.h index 6443d46a9..673b94fa5 100644 --- a/frameworks/taihe/media/include/avrecorder_callback_taihe.h +++ b/frameworks/taihe/media/include/avrecorder_callback_taihe.h @@ -32,6 +32,8 @@ public: void ClearCallbackReference(); void SendStateCallback(const std::string &state, const OHOS::Media::StateChangeReason &reason); void SendErrorCallback(int32_t errCode, const std::string &msg); + void SendAudioCaptureChangeCallback(const OHOS::Media::AudioRecorderChangeInfo &audioRecorderChangeInfo); + void SendPhotoAssertAvailableCallback(const std::string &uri); void SaveCallbackReference(const std::string &name, std::weak_ptr ref); void CancelCallbackReference(const std::string &name); std::string GetState(); @@ -40,6 +42,8 @@ public: protected: void OnError(RecorderErrorType errorType, int32_t errCode) override; void OnInfo(int32_t type, int32_t extra) override; + void OnAudioCaptureChange(const OHOS::Media::AudioRecorderChangeInfo &audioRecorderChangeInfo) override; + void OnPhotoAssertAvailable(const std::string &uri) override; private: struct AVRecordTaiheCallback { @@ -54,6 +58,13 @@ private: }; void OnTaiheStateCallBack(AVRecordTaiheCallback *taiheCb) const; void OnTaiheErrorCallBack(AVRecordTaiheCallback *taiheCb) const; +#ifdef SUPPORT_RECORDER_CREATE_FILE + void OnTaihePhotoAssertAvailableCallback(AVRecordTaiheCallback *jsCb) const; +#endif + void OnTaiheAudioCaptureChangeCallback(AVRecordTaiheCallback *taiheCb) const; + ::ohos::multimedia::audio::AudioDeviceDescriptor GetDeviceInfo(AVRecordTaiheCallback *taiheCb) const; + ::ohos::multimedia::audio::AudioCapturerChangeInfo GetAudioCapturerChangeInfo( + AVRecordTaiheCallback *taiheCb) const; std::mutex mutex_; std::string currentState_ = AVRecorderState::STATE_IDLE; diff --git a/frameworks/taihe/media/include/avrecorder_taihe.h b/frameworks/taihe/media/include/avrecorder_taihe.h index 08f4900df..64915493e 100644 --- a/frameworks/taihe/media/include/avrecorder_taihe.h +++ b/frameworks/taihe/media/include/avrecorder_taihe.h @@ -23,6 +23,7 @@ #include "media_core.h" #include "media_errors.h" #include "media_ani_common.h" +#include "pixel_map.h" namespace ANI::Media { using namespace taihe; @@ -184,12 +185,12 @@ public: const std::unique_ptr &asyncCtx); int32_t IsWatermarkSupported(bool &isWatermarkSupported); - void UpdateRotationSync(double rotation); + void UpdateRotationSync(int32_t rotation); int32_t GetRotation(std::unique_ptr &asyncCtx, int32_t rotation); std::shared_ptr> GetSetOrientationHintTask( const std::unique_ptr &asyncCtx); - double GetAudioCapturerMaxAmplitudeSync(); + int32_t GetAudioCapturerMaxAmplitudeSync(); std::shared_ptr> GetMaxAmplitudeTask( const std::unique_ptr &asyncCtx); int32_t GetMaxAmplitude(int32_t &maxAmplitude); @@ -207,6 +208,31 @@ public: std::vector<::ohos::multimedia::media::EncoderInfo> &TaiheEncoderInfos); ::ohos::multimedia::media::Range GetRange(int32_t min, int32_t max); + void SetWatermarkSync(::ohos::multimedia::image::image::weak::PixelMap watermark, + ::ohos::multimedia::media::WatermarkConfig const& config); + std::shared_ptr> SetWatermarkTask(const std::unique_ptr &asyncCtx); + int32_t SetWatermark(std::shared_ptr &pixelMap, + std::shared_ptr &watermarkConfig); + int32_t ConfigAVBufferMeta(std::shared_ptr &pixelMap, + std::shared_ptr &watermarkConfig, std::shared_ptr &meta); + int32_t GetWatermarkParameter(std::unique_ptr &asyncCtx, + ::ohos::multimedia::image::image::weak::PixelMap watermark, + ::ohos::multimedia::media::WatermarkConfig const& config); + int32_t GetWatermark(std::unique_ptr &asyncCtx, + ::ohos::multimedia::image::image::weak::PixelMap watermark); + int32_t GetWatermarkConfig(std::unique_ptr &asyncCtx, + ::ohos::multimedia::media::WatermarkConfig const& config); + + optional<::ohos::multimedia::audio::AudioCapturerChangeInfo> GetCurrentAudioCapturerInfoSync(); + std::shared_ptr> GetCurrentCapturerChangeInfoTask( + const std::unique_ptr &asyncCtx); + int32_t GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo &changeInfo); + ::ohos::multimedia::audio::AudioDeviceDescriptor GetDeviceInfo( + const std::unique_ptr &asyncCtx); + void GetAudioCapturerChangeInfo(const std::unique_ptr &asyncCtx, + ::ohos::multimedia::audio::AudioCapturerChangeInfo &res); + ::ohos::multimedia::audio::AudioCapturerChangeInfo GetAudioDefaultInfo(); + int32_t GetConfig(std::unique_ptr &asyncCtx, ohos::multimedia::media::AVRecorderConfig const& config); std::shared_ptr> GetPromiseTask(AVRecorderImpl *avtaihe, const std::string &opt); @@ -255,10 +281,14 @@ public: void ErrorCallback(int32_t errCode, const std::string &operate, const std::string &add); void OnError(callback_view callback); void OnStateChange(callback_view callback); + void OnAudioCapturerChange( + ::taihe::callback_view callback); void OnPhotoAssetAvailable(callback_view callback); void OffError(optional_view> callback); void OffStateChange(optional_view> callback); + void OffAudioCapturerChange(::taihe::optional_view<::taihe::callback> callback); void OffPhotoAssetAvailable(optional_view> callback); private: OHOS::sptr surface_ = nullptr; @@ -295,6 +325,7 @@ struct AVRecorderAsyncContext { std::vector encoderInfo_; OHOS::Media::MetaSourceType metaType_ = OHOS::Media::MetaSourceType::VIDEO_META_SOURCE_INVALID; std::shared_ptr watermarkConfig_ = nullptr; + std::shared_ptr pixelMap_ = nullptr; bool isWatermarkSupported_ = false; }; diff --git a/frameworks/taihe/media/include/avscreen_capture_taihe.h b/frameworks/taihe/media/include/avscreen_capture_taihe.h index d55f6e27b..880a58323 100644 --- a/frameworks/taihe/media/include/avscreen_capture_taihe.h +++ b/frameworks/taihe/media/include/avscreen_capture_taihe.h @@ -66,7 +66,7 @@ public: void InitSync(::ohos::multimedia::media::AVScreenCaptureRecordConfig const& config); void StartRecordingSync(); void StopRecordingSync(); - void SkipPrivacyModeSync(::taihe::array_view windowIDs); + void SkipPrivacyModeSync(::taihe::array_view windowIDs); void SetMicEnabledSync(bool enable); void ReleaseSync(); diff --git a/frameworks/taihe/media/include/avtranscoder_taihe.h b/frameworks/taihe/media/include/avtranscoder_taihe.h index a02484ace..503104c27 100644 --- a/frameworks/taihe/media/include/avtranscoder_taihe.h +++ b/frameworks/taihe/media/include/avtranscoder_taihe.h @@ -117,8 +117,8 @@ public: ohos::multimedia::media::AVFileDescriptor GetFdSrc(); void SetFdSrc(ohos::multimedia::media::AVFileDescriptor const& fdSrc); - double GetFdDst(); - void SetFdDst(double fdDst); + int32_t GetFdDst(); + void SetFdDst(int32_t fdDst); void PrepareSync(AVTranscoderConfig const& config); RetInfo Start(); RetInfo Pause(); @@ -156,8 +156,8 @@ public: void OnError(callback_view callback); void OffError(optional_view> callback); - void OnProgressUpdate(callback_view callback); - void OffProgressUpdate(optional_view> callback); + void OnProgressUpdate(callback_view callback); + void OffProgressUpdate(optional_view> callback); using AvTransCoderTaskqFunc = RetInfo (AVTranscoderImpl::*)(); private: diff --git a/frameworks/taihe/media/include/helper_data_source_callback_taihe.h b/frameworks/taihe/media/include/helper_data_source_callback_taihe.h index 33f025acb..b38d7b8b8 100644 --- a/frameworks/taihe/media/include/helper_data_source_callback_taihe.h +++ b/frameworks/taihe/media/include/helper_data_source_callback_taihe.h @@ -23,7 +23,7 @@ namespace OHOS { namespace Media { -using DataSrcCallback = taihe::callback, double, taihe::optional_view)>; +using DataSrcCallback = taihe::callback, int64_t, taihe::optional_view)>; struct HelperDataSourceTHCallback { HelperDataSourceTHCallback(const std::string &callbackName, const std::shared_ptr &mem, diff --git a/frameworks/taihe/media/include/media_source_loading_request_taihe.h b/frameworks/taihe/media/include/media_source_loading_request_taihe.h index 7e0946fd4..b4a79168a 100644 --- a/frameworks/taihe/media/include/media_source_loading_request_taihe.h +++ b/frameworks/taihe/media/include/media_source_loading_request_taihe.h @@ -29,7 +29,7 @@ public: MediaSourceLoadingRequestImpl(uint64_t requestId); string GetUrl(); optional> GetHeader(); - optional RespondData(double uuid, double offset, array_view buffer); + optional RespondData(double uuid, double offset, array_view buffer); void RespondHeader(double uuid, optional_view> header, optional_view redirectUrl); void FinishLoading(double uuid, LoadingRequestError state); static ::ohos::multimedia::media::MediaSourceLoadingRequest CreateLoadingRequest( diff --git a/frameworks/taihe/media/include/media_source_taihe.h b/frameworks/taihe/media/include/media_source_taihe.h index f99ee7e7a..f14fd25f6 100644 --- a/frameworks/taihe/media/include/media_source_taihe.h +++ b/frameworks/taihe/media/include/media_source_taihe.h @@ -31,9 +31,10 @@ using namespace OHOS::Media; class MediaSourceImpl { public: - static std::shared_ptr GetMediaSource(weak::MediaSource mediaSource); + static std::shared_ptr GetMediaSource(ohos::multimedia::media::weak::MediaSource mediaSource); static std::shared_ptr GetMediaSource(MediaSourceImpl *mediaSourceImpl); - static std::shared_ptr GetSourceLoader(weak::MediaSource mediaSource); + static std::shared_ptr GetSourceLoader( + ohos::multimedia::media::weak::MediaSource mediaSource); MediaSourceImpl(string_view url, optional_view> headers); MediaSourceImpl(array_view<::ohos::multimedia::media::MediaStream> streams); int64_t GetImplPtr(); diff --git a/frameworks/taihe/media/include/media_taihe_utils.h b/frameworks/taihe/media/include/media_taihe_utils.h index 3992c62ea..8ec6ecbf2 100644 --- a/frameworks/taihe/media/include/media_taihe_utils.h +++ b/frameworks/taihe/media/include/media_taihe_utils.h @@ -17,6 +17,8 @@ #include "ohos.multimedia.media.proj.hpp" #include "ohos.multimedia.media.impl.hpp" +#include "ohos.multimedia.audio.proj.hpp" +#include "ohos.multimedia.audio.impl.hpp" #include "audio_info.h" #include "taihe/runtime.hpp" #include "audio_effect.h" @@ -31,11 +33,6 @@ using namespace taihe; using namespace ohos::multimedia::media; constexpr char CLASS_NAME_BUSINESSERROR[] = "@ohos.base.BusinessError"; - -struct MediaKeySystemInfo { - std::string uuid; - std::vector pssh; -}; class MediaTaiheUtils { public: static string ToTaiheString(const std::string &src); @@ -46,7 +43,6 @@ public: static bool GetEnumKeyByStringValue(::taihe::string_view value, typename EnumTypeString::key_t &key); static ani_object ToBusinessError(ani_env *env, int32_t code, const std::string &message); static ani_object CreatePixelMap(ani_env *env, OHOS::Media::PixelMap &pixelMap); - static ani_object CreateMediaKeySystemInfo(ani_env *env, ANI::Media::MediaKeySystemInfo &mediaKeySystemInfo); static ani_string ToAniString(ani_env *env, const std::string &str); static uintptr_t GetUndefined(ani_env* env); static map CreateFormatBuffer(OHOS::Media::Format &format); diff --git a/frameworks/taihe/media/src/avimagegenerator_taihe.cpp b/frameworks/taihe/media/src/avimagegenerator_taihe.cpp index 0dbab8041..7d01f9aa3 100644 --- a/frameworks/taihe/media/src/avimagegenerator_taihe.cpp +++ b/frameworks/taihe/media/src/avimagegenerator_taihe.cpp @@ -18,6 +18,7 @@ #include "media_errors.h" #include "media_dfx.h" #include "fd_utils.h" +#include "pixel_map_taihe.h" using namespace ANI::Media; @@ -39,8 +40,8 @@ optional AVImageGeneratorImpl::GetFdSrc() MEDIA_LOGI("GetFdSrc In"); AVFileDescriptor fdSrc; fdSrc.fd = fileDescriptor_.fd; - fdSrc.offset = optional(std::in_place_t{}, fileDescriptor_.offset); - fdSrc.length = optional(std::in_place_t{}, fileDescriptor_.length); + fdSrc.offset = optional(std::in_place_t{}, fileDescriptor_.offset); + fdSrc.length = optional(std::in_place_t{}, fileDescriptor_.length); MEDIA_LOGI("GetFdSrc Out"); return optional(std::in_place_t{}, fdSrc); } @@ -53,7 +54,7 @@ void AVImageGeneratorImpl::SetFdSrc(optional_view fdSrc) CHECK_AND_RETURN_LOG(state_ == OHOS::Media::HelperState::HELPER_STATE_IDLE, "Has set source once, unsupport set again"); CHECK_AND_RETURN_LOG(helper_ != nullptr, "Invalid AVImageGenerator."); - + if (fdSrc.has_value()) { fileDescriptor_.fd = fdSrc.value().fd; if (fdSrc.value().offset.has_value()) { @@ -80,6 +81,38 @@ void AVImageGeneratorImpl::SetFdSrc(optional_view fdSrc) return; } +::ohos::multimedia::image::image::PixelMap AVImageGeneratorImpl::FetchFrameByTimeSync(int64_t timeUs, + ::ohos::multimedia::media::AVImageQueryOptions options, ::ohos::multimedia::media::PixelMapParams const& param) +{ + OHOS::Media::MediaTrace trace("AVImageGeneratorTaihe::FetchFrameByTimeSync"); + MEDIA_LOGI("FetchFrameByTimeSync in"); + AVImageGeneratorImpl *taihe = this; + if (taihe->state_ != OHOS::Media::HelperState::HELPER_STATE_RUNNABLE) { + set_business_error(OHOS::Media::MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "Current state is not runnable, can't fetchFrame."); + } + timeUs_ = timeUs; + option_ = options; + if (param.height.has_value() && param.width.has_value() && param.colorFormat.has_value()) { + param_.dstWidth = static_cast(param.width.value()); + param_.dstHeight = static_cast(param.height.value()); + OHOS::Media::PixelFormat colorFormat = OHOS::Media::PixelFormat::RGBA_8888; + int32_t formatVal = 3; + formatVal = static_cast(param.colorFormat.value()); + colorFormat = static_cast(formatVal); + if (colorFormat != OHOS::Media::PixelFormat::RGB_565 && colorFormat != + OHOS::Media::PixelFormat::RGB_888 && + colorFormat != OHOS::Media::PixelFormat::RGBA_8888) { + set_business_error(OHOS::Media::MSERR_INVALID_VAL, "formatVal is invalid"); + } + param_.colorFormat = colorFormat; + } + + auto pixelMap = helper_->FetchFrameYuv(timeUs_, option_, param_); + pixel_ = pixelMap; + return Image::PixelMapImpl::CreatePixelMap(pixel_); +} + void AVImageGeneratorImpl::ReleaseSync() { OHOS::Media::MediaTrace trace("AVImageGeneratorTaihe::ReleaseSync"); diff --git a/frameworks/taihe/media/src/avmetadataextractor_taihe.cpp b/frameworks/taihe/media/src/avmetadataextractor_taihe.cpp index ccefa3aa7..ebe2c8880 100644 --- a/frameworks/taihe/media/src/avmetadataextractor_taihe.cpp +++ b/frameworks/taihe/media/src/avmetadataextractor_taihe.cpp @@ -15,6 +15,7 @@ #include "avmetadataextractor_taihe.h" #include "media_log.h" +#include "pixel_map_taihe.h" #include "media_errors.h" #include "media_dfx.h" #include "image_source.h" @@ -40,8 +41,8 @@ optional AVMetadataExtractorImpl::GetFdSrc() MEDIA_LOGI("TaiheGetAVFileDescriptor In"); AVFileDescriptor fdSrc; fdSrc.fd = fileDescriptor_.fd; - fdSrc.offset = optional(std::in_place_t{}, fileDescriptor_.offset); - fdSrc.length = optional(std::in_place_t{}, fileDescriptor_.length); + fdSrc.offset = optional(std::in_place_t{}, fileDescriptor_.offset); + fdSrc.length = optional(std::in_place_t{}, fileDescriptor_.length); MEDIA_LOGI("TaiheGetAVFileDescriptor Out"); return optional(std::in_place_t{}, fdSrc); } @@ -84,7 +85,7 @@ optional AVMetadataExtractorImpl::GetDataSrc() MEDIA_LOGI("TaiheGetDataSrc In"); CHECK_AND_RETURN_RET_LOG(dataSrcCb_ != nullptr, optional(std::nullopt), "failed to check dataSrcCb_"); - + int64_t fileSize; (void)dataSrcCb_->GetSize(fileSize); const std::string callbackName = "readAt"; @@ -92,7 +93,7 @@ optional AVMetadataExtractorImpl::GetDataSrc() int32_t ret = dataSrcCb_->GetCallback(callbackName, callback); CHECK_AND_RETURN_RET_LOG(ret == OHOS::Media::MSERR_OK, optional(std::nullopt), "failed to GetCallback"); - + auto cacheCallback = std::reinterpret_pointer_cast(callback); AVDataSrcDescriptor fdSrc = AVDataSrcDescriptor{std::move(fileSize), std::move(*cacheCallback)}; MEDIA_LOGI("TaiheGetDataSrc Out"); @@ -286,6 +287,42 @@ optional CreateAVMetadataExtractorSync() return optional(std::in_place_t{}, res); } +static std::unique_ptr ConvertMemToPixelMap( + std::shared_ptr sharedMemory) +{ + CHECK_AND_RETURN_RET_LOG(sharedMemory != nullptr, nullptr, "SharedMem is nullptr"); + MEDIA_LOGI("FetchArtPicture size: %{public}d", sharedMemory->GetSize()); + OHOS::Media::SourceOptions sourceOptions; + uint32_t errorCode = 0; + std::unique_ptr imageSource = + OHOS::Media::ImageSource::CreateImageSource(sharedMemory->GetBase(), sharedMemory->GetSize(), + sourceOptions, errorCode); + CHECK_AND_RETURN_RET_LOG(imageSource != nullptr, nullptr, "Failed to create imageSource."); + OHOS::Media::DecodeOptions decodeOptions; + std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOptions, errorCode); + CHECK_AND_RETURN_RET_LOG(pixelMap != nullptr, nullptr, "Failed to decode imageSource"); + return pixelMap; +} + +ohos::multimedia::image::image::PixelMap AVMetadataExtractorImpl::FetchAlbumCoverSync() +{ + OHOS::Media::MediaTrace trace("AVMetadataExtractorTaihe::fetchArtPicture"); + MEDIA_LOGI("TaiheFetchArtPicture In"); + + if (state_ != OHOS::Media::HelperState::HELPER_STATE_RUNNABLE) { + set_business_error(OHOS::Media::MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "Can't fetchAlbumCover, please set fdSrc or dataSrc."); + } + + MEDIA_LOGI("TaiheFetchArtPicture task start"); + auto sharedMemory = helper_->FetchArtPicture(); + std::shared_ptr artPicture = ConvertMemToPixelMap(sharedMemory); + if (artPicture == nullptr) { + set_business_error(OHOS::Media::MSERR_EXT_API9_UNSUPPORT_FORMAT, "Failed to fetchAlbumCover"); + } + return Image::PixelMapImpl::CreatePixelMap(artPicture); +} + void AVMetadataExtractorImpl::ReleaseSync() { OHOS::Media::MediaTrace trace("AVMetadataExtractorTaihe::release"); @@ -300,7 +337,7 @@ void AVMetadataExtractorImpl::ReleaseSync() helper_->Release(); } -double AVMetadataExtractorImpl::GetFrameIndexByTimeSync(double timeUs) +int32_t AVMetadataExtractorImpl::GetFrameIndexByTimeSync(double timeUs) { OHOS::Media::MediaTrace trace("AVMetadataExtractorImpl::GetFrameIndexByTimeSync"); timeStamp_ = static_cast(timeUs); @@ -316,10 +353,10 @@ double AVMetadataExtractorImpl::GetFrameIndexByTimeSync(double timeUs) set_business_error(OHOS::Media::MSERR_EXT_API9_UNSUPPORT_FORMAT, "Demuxer getFrameIndexByTime failed."); return -1; } - return static_cast(index_); + return static_cast(index_); } -double AVMetadataExtractorImpl::GetTimeByFrameIndexSync(double index) +double AVMetadataExtractorImpl::GetTimeByFrameIndexSync(int32_t index) { OHOS::Media::MediaTrace trace("AVMetadataExtractorImpl::GetTimeByFrameIndexSync"); if (index < 0) { diff --git a/frameworks/taihe/media/src/avplayer_callback_taihe.cpp b/frameworks/taihe/media/src/avplayer_callback_taihe.cpp index cc40be8dd..5c986d304 100644 --- a/frameworks/taihe/media/src/avplayer_callback_taihe.cpp +++ b/frameworks/taihe/media/src/avplayer_callback_taihe.cpp @@ -40,6 +40,54 @@ OHOS::AudioStandard::InterruptEvent interruptEvent_ = OHOS::AudioStandard::Inter class AniCallback { public: + + static ohos::multimedia::audio::AudioDeviceDescriptor GetDeviceInfo( + OHOS::AudioStandard::AudioDeviceDescriptor deviceInfo) + { + ohos::multimedia::audio::DeviceRole::key_t deviceRoleKey; + MediaTaiheUtils::GetEnumKeyByValue( + deviceInfo.deviceRole_, deviceRoleKey); + ohos::multimedia::audio::DeviceType::key_t deviceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + deviceInfo.deviceType_, deviceTypeKey); + taihe::string name = MediaTaiheUtils::ToTaiheString(deviceInfo.deviceName_); + taihe::string address = MediaTaiheUtils::ToTaiheString(deviceInfo.macAddress_); + std::vector samplingRateVec( + deviceInfo.audioStreamInfo_.samplingRate.begin(), + deviceInfo.audioStreamInfo_.samplingRate.end()); + std::vector channelsVec(deviceInfo.audioStreamInfo_.channels.begin(), + deviceInfo.audioStreamInfo_.channels.end()); + taihe::string networkId = MediaTaiheUtils::ToTaiheString(deviceInfo.networkId_); + taihe::string displayName = MediaTaiheUtils::ToTaiheString( + deviceInfo.displayName_); + ohos::multimedia::audio::AudioEncodingType::key_t audioEncodingTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + deviceInfo.audioStreamInfo_.encoding, audioEncodingTypeKey); + std::vector channelMasks; + channelMasks.push_back(deviceInfo.channelMasks_); + std::vector audioEncodingType; + audioEncodingType.push_back(audioEncodingTypeKey); + + ohos::multimedia::audio::AudioDeviceDescriptor descriptor { + std::move(ohos::multimedia::audio::DeviceRole(deviceRoleKey)), + std::move(ohos::multimedia::audio::DeviceType(deviceTypeKey)), + std::move(deviceInfo.deviceId_), + std::move(name), + std::move(address), + array(samplingRateVec), + array(channelsVec), + array(channelMasks), + std::move(networkId), + std::move(deviceInfo.interruptGroupId_), + std::move(deviceInfo.volumeGroupId_), + std::move(displayName), + optional<::taihe::array>( + std::in_place_t{}, array(audioEncodingType)), + optional(std::nullopt), + optional(std::nullopt), + }; + return descriptor; + } struct Base { std::weak_ptr callback; std::string callbackName = "unknown"; @@ -91,8 +139,8 @@ public: "%{public}s AutoRef is nullptr", callbackName.c_str()); auto func = intRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); (*cacheCallback)(value); } }; @@ -109,9 +157,9 @@ public: int32_t val = 0; auto func = intVecRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> + std::shared_ptr> cacheCallback = std::reinterpret_pointer_cast>(func); + (ohos::multimedia::media::BufferingInfoType, int32_t)>>(func); ohos::multimedia::media::BufferingInfoType::key_t key; MediaTaiheUtils::GetEnumKeyByValue(firstValueAsDouble, key); (*cacheCallback)(ohos::multimedia::media::BufferingInfoType(key), val); @@ -126,17 +174,15 @@ public: CHECK_AND_RETURN_LOG(intVecRef != nullptr, "%{public}s AutoRef is nullptr", callbackName.c_str()); CHECK_AND_RETURN_LOG(valueVec.size() > 1, "valueVec size is less than 2"); - double firstValueAsDouble = static_cast(valueVec[0]); - double secondValueAsDouble = static_cast(valueVec[1]); auto func = intVecRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); - (*cacheCallback)(firstValueAsDouble, secondValueAsDouble); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + (*cacheCallback)(valueVec[0], valueVec[1]); } }; struct IntArray : public Base { - std::vector valueVec; + std::vector valueVec; void UvWork() override { std::shared_ptr intVecRef = callback.lock(); @@ -144,8 +190,8 @@ public: "%{public}s AutoRef is nullptr", callbackName.c_str()); auto func = intVecRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr)>> cacheCallback = - std::reinterpret_pointer_cast)>>(func); + std::shared_ptr)>> cacheCallback = + std::reinterpret_pointer_cast)>>(func); (*cacheCallback)(valueVec); } }; @@ -211,8 +257,8 @@ public: CHECK_AND_RETURN_LOG(trackChangeRef != nullptr, "%{public}s AutoRef is nullptr", callbackName.c_str()); auto func = trackChangeRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); (*cacheCallback)(number, isSelect); } }; @@ -251,7 +297,7 @@ public: }; struct SeiInfoUpadte : public Base { - double playbackPosition; + int32_t playbackPosition; std::vector payloadGroup; void UvWork() override { @@ -259,9 +305,9 @@ public: CHECK_AND_RETURN_LOG(seiInfoRef != nullptr, "%{public}s AutoRef is nullptr", callbackName.c_str()); auto func = seiInfoRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr, optional_view)>> cacheCallback = + std::shared_ptr, optional_view)>> cacheCallback = std::reinterpret_pointer_cast, - optional_view)>>(func); + optional_view)>>(func); std::vector seiMessages; for (const auto& format : payloadGroup) { uint8_t* bufferData = nullptr; @@ -283,10 +329,84 @@ public: seiMessages.push_back(seiMessage); } array_view seiMessageView(seiMessages); - (*cacheCallback)(seiMessageView, optional_view(&playbackPosition)); + (*cacheCallback)(seiMessageView, optional_view(&playbackPosition)); + } + }; + struct PropertyInt : public Base { + std::map valueMap; + void UvWork() override + { + std::shared_ptr propertyIntRef = callback.lock(); + CHECK_AND_RETURN_LOG(propertyIntRef != nullptr, + "%{public}s AutoRef is nullptr", callbackName.c_str()); + + auto func = propertyIntRef->callbackRef_; + CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + + ohos::multimedia::audio::InterruptType::key_t eventTypeKey; + MediaTaiheUtils::GetEnumKeyByValue(interruptEvent_.eventType, + eventTypeKey); + valueMap["eventType"] = static_cast(eventTypeKey); + + ohos::multimedia::audio::InterruptForceType::key_t forceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue(interruptEvent_.forceType, + forceTypeKey); + + valueMap["forceType"] = static_cast(forceTypeKey); + ohos::multimedia::audio::InterruptHint::key_t hintTypeKey; + MediaTaiheUtils::GetEnumKeyByValue(interruptEvent_.hintType, + hintTypeKey); + + valueMap["hintType"] = static_cast(hintTypeKey); + + ohos::multimedia::audio::InterruptEvent interruptEvent = { + .eventType = ohos::multimedia::audio::InterruptType(static_cast< + ohos::multimedia::audio::InterruptType::key_t>(valueMap["eventType"])), + .forceType = ohos::multimedia::audio::InterruptForceType(static_cast< + ohos::multimedia::audio::InterruptForceType::key_t>(valueMap["forceType"])), + .hintType = ohos::multimedia::audio::InterruptHint(static_cast< + ohos::multimedia::audio::InterruptHint::key_t>(valueMap["hintType"])), + }; + + (*cacheCallback)(interruptEvent); } }; + struct DeviceChangeAni : public Base { + OHOS::AudioStandard::AudioDeviceDescriptor deviceInfo = + OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::AudioDeviceDescriptor::DEVICE_INFO); + int32_t reason; + void UvWork() override + { + std::shared_ptr deviceChangeRef = callback.lock(); + CHECK_AND_RETURN_LOG(deviceChangeRef != nullptr, "%{public}s AutoRef is nullptr", callbackName.c_str()); + + auto func = deviceChangeRef->callbackRef_; + CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); + std::shared_ptr> + cacheCallback = std::reinterpret_pointer_cast< + taihe::callback>(func); + + std::vector audioDeviceDescriptor; + audioDeviceDescriptor.push_back(GetDeviceInfo(deviceInfo)); + + ohos::multimedia::audio::AudioStreamDeviceChangeReason::key_t changeReasonKey; + MediaTaiheUtils::GetEnumKeyByValue( + reason, changeReasonKey); + ohos::multimedia::audio::AudioStreamDeviceChangeReason changeReason = + static_cast(changeReasonKey); + + ohos::multimedia::audio::AudioStreamDeviceChangeInfo audioStreamDeviceChangeInfo = { + array(audioDeviceDescriptor), + std::move(changeReason), + }; + + (*cacheCallback)(audioStreamDeviceChangeInfo); + } + }; struct ObjectArray : public Base { std::multimap> infoMap; void UvWork() override @@ -297,12 +417,17 @@ public: auto func = mapRef->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); - ANI::Media::MediaKeySystemInfo mediaKeySystemInfo; - ani_object aniObject = MediaTaiheUtils::CreateMediaKeySystemInfo(get_env(), mediaKeySystemInfo); - uintptr_t objectArray = reinterpret_cast(&aniObject); - (*cacheCallback)(objectArray); + std::shared_ptr data)>> cacheCallback = + std::reinterpret_pointer_cast data)>>(func); + std::vector infoArray; + for (auto item : infoMap) { + MediaKeySystemInfo info{ + item.first, + array(copy_data_t{}, item.second.data(), item.second.size()) + }; + infoArray.push_back(info); + } + (*cacheCallback)(array(copy_data_t{}, infoArray.data(), infoArray.size())); } }; @@ -323,8 +448,8 @@ public: (::ohos::multimedia::media::SubtitleInfo const&)>>(func); ::ohos::multimedia::media::SubtitleInfo subtitleInfo; subtitleInfo.text = ::taihe::optional(std::in_place_t{}, valueMap.text); - subtitleInfo.startTime = taihe::optional(std::in_place_t{}, valueMap.pts); - subtitleInfo.duration = taihe::optional(std::in_place_t{}, valueMap.duration); + subtitleInfo.startTime = taihe::optional(std::in_place_t{}, valueMap.pts); + subtitleInfo.duration = taihe::optional(std::in_place_t{}, valueMap.duration); (*cacheCallback)(subtitleInfo); } }; @@ -429,6 +554,10 @@ AVPlayerCallback::AVPlayerCallback(AVPlayerNotify *listener) [this](const int32_t extra, const Format &infoBody) { OnSeiInfoCb(extra, infoBody); } }, { INFO_TYPE_SUBTITLE_UPDATE_INFO, [this](const int32_t extra, const Format &infoBody) { OnSubtitleInfoCb(extra, infoBody); } }, + { INFO_TYPE_INTERRUPT_EVENT, + [this](const int32_t extra, const Format &infoBody) { OnAudioInterruptCb(extra, infoBody); } }, + { INFO_TYPE_AUDIO_DEVICE_CHANGE, + [this](const int32_t extra, const Format &infoBody) { OnAudioDeviceChangeCb(extra, infoBody); } }, }; } @@ -709,7 +838,7 @@ void AVPlayerCallback::OnBitRateCollectedCb(const int32_t extra, const Format &i return; } - std::vector bitrateVec; + std::vector bitrateVec; if (infoBody.ContainKey(std::string(PlayerKeys::PLAYER_AVAILABLE_BITRATES))) { uint8_t *addr = nullptr; size_t size = 0; @@ -726,7 +855,7 @@ void AVPlayerCallback::OnBitRateCollectedCb(const int32_t extra, const Format &i MEDIA_LOGI("bitrate = %{public}u", bitrate); addr += sizeof(uint32_t); size -= sizeof(uint32_t); - bitrateVec.push_back(static_cast(bitrate)); + bitrateVec.push_back(static_cast(bitrate)); } } @@ -1014,6 +1143,67 @@ void AVPlayerCallback::OnSubtitleInfoCb(const int32_t extra, const Format &infoB AniCallback::CompleteCallback(cb, mainHandler_); } +void AVPlayerCallback::OnAudioInterruptCb(const int32_t extra, const Format &infoBody) +{ + (void)extra; + CHECK_AND_RETURN_LOG(isLoaded_.load(), "current source is unready"); + if (refMap_.find(AVPlayerEvent::EVENT_AUDIO_INTERRUPT) == refMap_.end()) { + MEDIA_LOGI("can not find audio interrupt callback!"); + return; + } + + AniCallback::PropertyInt *cb = new(std::nothrow) AniCallback::PropertyInt(); + CHECK_AND_RETURN_LOG(cb != nullptr, "failed to new PropertyInt"); + + cb->callback = refMap_.at(AVPlayerEvent::EVENT_AUDIO_INTERRUPT); + cb->callbackName = AVPlayerEvent::EVENT_AUDIO_INTERRUPT; + int32_t eventType = 0; + int32_t forceType = 0; + int32_t hintType = 0; + (void)infoBody.GetIntValue(PlayerKeys::AUDIO_INTERRUPT_TYPE, eventType); + (void)infoBody.GetIntValue(PlayerKeys::AUDIO_INTERRUPT_FORCE, forceType); + (void)infoBody.GetIntValue(PlayerKeys::AUDIO_INTERRUPT_HINT, hintType); + MEDIA_LOGI("OnAudioInterruptCb is called, eventType = %{public}d, forceType = %{public}d, hintType = %{public}d", + eventType, forceType, hintType); + // ohos.multimedia.audio.d.ts interface InterruptEvent + cb->valueMap["eventType"] = eventType; + cb->valueMap["forceType"] = forceType; + cb->valueMap["hintType"] = hintType; + AniCallback::CompleteCallback(cb, mainHandler_); +} + +void AVPlayerCallback::OnAudioDeviceChangeCb(const int32_t extra, const Format &infoBody) +{ + (void)extra; + CHECK_AND_RETURN_LOG(isLoaded_.load(), "current source is unready"); + if (refMap_.find(AVPlayerEvent::EVENT_AUDIO_DEVICE_CHANGE) == refMap_.end()) { + MEDIA_LOGI("0x%{public}06" PRIXPTR " can not find audio AudioDeviceChange callback!", FAKE_POINTER(this)); + return; + } + + AniCallback::DeviceChangeAni *cb = new(std::nothrow) AniCallback::DeviceChangeAni(); + CHECK_AND_RETURN_LOG(cb != nullptr, "failed to new DeviceChangeTaihe"); + + cb->callback = refMap_.at(AVPlayerEvent::EVENT_AUDIO_DEVICE_CHANGE); + cb->callbackName = AVPlayerEvent::EVENT_AUDIO_DEVICE_CHANGE; + + uint8_t *parcelBuffer = nullptr; + size_t parcelSize; + infoBody.GetBuffer(PlayerKeys::AUDIO_DEVICE_CHANGE, &parcelBuffer, parcelSize); + OHOS::Parcel parcel; + parcel.WriteBuffer(parcelBuffer, parcelSize); + OHOS::AudioStandard::AudioDeviceDescriptor deviceInfo(OHOS::AudioStandard::AudioDeviceDescriptor::DEVICE_INFO); + deviceInfo.Unmarshalling(parcel); + + int32_t reason; + infoBody.GetIntValue(PlayerKeys::AUDIO_DEVICE_CHANGE_REASON, reason); + + cb->deviceInfo = deviceInfo; + cb->reason = reason; + + AniCallback::CompleteCallback(cb, mainHandler_); +} + int32_t AVPlayerCallback::SetDrmInfoData(const uint8_t *drmInfoAddr, int32_t infoCount, std::multimap> &drmInfoMap) { diff --git a/frameworks/taihe/media/src/avplayer_taihe.cpp b/frameworks/taihe/media/src/avplayer_taihe.cpp index f741e9758..6738efa4d 100644 --- a/frameworks/taihe/media/src/avplayer_taihe.cpp +++ b/frameworks/taihe/media/src/avplayer_taihe.cpp @@ -18,6 +18,9 @@ #include "media_errors.h" #include "media_taihe_utils.h" #include "media_dfx.h" +#ifdef SUPPORT_AVPLAYER_DRM +#include "key_session_taihe.h" +#endif #ifdef SUPPORT_VIDEO #include "surface_utils.h" #endif @@ -29,7 +32,7 @@ #endif using namespace ANI::Media; -using DataSrcCallback = taihe::callback, double, taihe::optional_view)>; +using DataSrcCallback = taihe::callback, int64_t, taihe::optional_view)>; namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_METADATA, "AVPlayerTaihe"}; @@ -109,7 +112,60 @@ void AVPlayerImpl::SetUrl(optional_view url) MEDIA_LOGI("0x%{public}06" PRIXPTR " SetUrl Out", FAKE_POINTER(this)); } -double AVPlayerImpl::GetWidth() +optional AVPlayerImpl::GetAudioEffectMode() +{ + MediaTrace trace("AVPlayerImpl::GetAudioEffectMode"); + MEDIA_LOGI("TaiheGetAudioEffectMode In"); + ohos::multimedia::audio::AudioEffectMode::key_t audioEffectModeKey; + MediaTaiheUtils::GetEnumKeyByValue(audioEffectMode_, audioEffectModeKey); + ::ohos::multimedia::audio::AudioEffectMode changeReason = + static_cast<::ohos::multimedia::audio::AudioEffectMode>(audioEffectModeKey); + ::ohos::multimedia::audio::AudioEffectMode audioEffectMode = { + changeReason, + }; + + return optional(std::in_place_t{}, audioEffectMode); +} + +void AVPlayerImpl::SetAudioEffectMode(optional_view audioEffectMode) +{ + MediaTrace trace("AVPlayerImpl::SetAudioEffectMode"); + MEDIA_LOGI("TaiheSetAudioEffectMode In"); + + if (!IsControllable()) { + OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "current state is not prepared/playing/paused/completed, unsupport audio effect mode operation"); + return; + } + if (audioEffectMode.has_value()) { + int32_t effectMode = static_cast(audioEffectMode.value()); + if (effectMode > OHOS::AudioStandard::AudioEffectMode::EFFECT_DEFAULT || + effectMode < OHOS::AudioStandard::AudioEffectMode::EFFECT_NONE) { + OnErrorCb(MSERR_EXT_API9_INVALID_PARAMETER, + "invalid audioEffectMode, please check the input audio effect Mode"); + return; + } + if (audioEffectMode_ == effectMode) { + MEDIA_LOGI("Same effectMode parameter"); + return; + } + audioEffectMode_ = effectMode; + auto task = std::make_shared>([this, effectMode]() { + MEDIA_LOGI("TaiheSetAudioEffectMode Task in"); + if (player_ != nullptr) { + Format format; + (void)format.PutIntValue(PlayerKeys::AUDIO_EFFECT_MODE, effectMode); + (void)player_->SetParameter(format); + } + MEDIA_LOGI("TaiheSetAudioEffectMode Task out"); + }); + (void)taskQue_->EnqueueTask(task); + } + MEDIA_LOGI("TaiheSetAudioEffectMode Out"); + return; +} + +int32_t AVPlayerImpl::GetWidth() { MediaTrace trace("AVPlayerImpl::get width"); MEDIA_LOGI("TaiheGetWidth"); @@ -122,7 +178,7 @@ double AVPlayerImpl::GetWidth() return width; } -double AVPlayerImpl::GetHeight() +int32_t AVPlayerImpl::GetHeight() { MediaTrace trace("AVPlayerImpl::get height"); MEDIA_LOGI("TaiheGetHeight"); @@ -147,7 +203,7 @@ string AVPlayerImpl::GetState() return curState; } -double AVPlayerImpl::GetDuration() +int32_t AVPlayerImpl::GetDuration() { MediaTrace trace("AVPlayerImpl::get duration"); MEDIA_LOGD("TaiheGetDuration In"); @@ -162,7 +218,7 @@ double AVPlayerImpl::GetDuration() return duration; } -double AVPlayerImpl::GetCurrentTime() +int32_t AVPlayerImpl::GetCurrentTime() { MediaTrace trace("AVPlayerImpl::get currentTime"); MEDIA_LOGD("TaiheGetCurrentTime In"); @@ -216,6 +272,163 @@ void AVPlayerImpl::SetVolume(double volume) return; } +optional AVPlayerImpl::GetAudioRendererInfo() +{ + MediaTrace trace("AVPlayerImpl::get audioRendererInfo"); + MEDIA_LOGI("TaiheGetAudioRendererInfo In"); + ohos::multimedia::audio::StreamUsage::key_t streamUsageKey; + MediaTaiheUtils::GetEnumKeyByValue(audioRendererInfo_.streamUsage, + streamUsageKey); + ohos::multimedia::audio::StreamUsage streamUsage = ohos::multimedia::audio::StreamUsage(streamUsageKey); + int32_t rendererFlags = audioRendererInfo_.rendererFlags; + ohos::multimedia::audio::AudioVolumeMode::key_t volumeModeKey; + MediaTaiheUtils::GetEnumKeyByValue(audioRendererInfo_.volumeMode, + volumeModeKey); + ohos::multimedia::audio::AudioVolumeMode volumeMode = ohos::multimedia::audio::AudioVolumeMode(volumeModeKey); + + ohos::multimedia::audio::AudioRendererInfo result = { + std::move(streamUsage), std::move(rendererFlags), + optional(std::in_place_t{}, volumeMode) + }; + MEDIA_LOGI("GetAudioRendererInfo Out"); + + return optional(std::in_place_t{}, result); +} + +bool AVPlayerImpl::HandleParameter(ohos::multimedia::audio::AudioRendererInfo src, + OHOS::AudioStandard::AudioRendererInfo &audioRendererInfo) +{ + int32_t content = OHOS::AudioStandard::CONTENT_TYPE_UNKNOWN; + int32_t usage = -1; + int32_t rendererFlags = -1; + int32_t volumeMode = -1; + std::vector contents = { + OHOS::AudioStandard::CONTENT_TYPE_UNKNOWN, OHOS::AudioStandard::CONTENT_TYPE_SPEECH, + OHOS::AudioStandard::CONTENT_TYPE_MUSIC, OHOS::AudioStandard::CONTENT_TYPE_MOVIE, + OHOS::AudioStandard::CONTENT_TYPE_SONIFICATION, OHOS::AudioStandard::CONTENT_TYPE_RINGTONE + }; + std::vector usages = { + OHOS::AudioStandard::STREAM_USAGE_UNKNOWN, OHOS::AudioStandard::STREAM_USAGE_MEDIA, + OHOS::AudioStandard::STREAM_USAGE_MUSIC, OHOS::AudioStandard::STREAM_USAGE_VOICE_COMMUNICATION, + OHOS::AudioStandard::STREAM_USAGE_VOICE_ASSISTANT, OHOS::AudioStandard::STREAM_USAGE_ALARM, + OHOS::AudioStandard::STREAM_USAGE_VOICE_MESSAGE, OHOS::AudioStandard::STREAM_USAGE_NOTIFICATION_RINGTONE, + OHOS::AudioStandard::STREAM_USAGE_RINGTONE, OHOS::AudioStandard::STREAM_USAGE_NOTIFICATION, + OHOS::AudioStandard::STREAM_USAGE_ACCESSIBILITY, OHOS::AudioStandard::STREAM_USAGE_SYSTEM, + OHOS::AudioStandard::STREAM_USAGE_MOVIE, OHOS::AudioStandard::STREAM_USAGE_GAME, + OHOS::AudioStandard::STREAM_USAGE_AUDIOBOOK, OHOS::AudioStandard::STREAM_USAGE_NAVIGATION, + OHOS::AudioStandard::STREAM_USAGE_DTMF, OHOS::AudioStandard::STREAM_USAGE_ENFORCED_TONE, + OHOS::AudioStandard::STREAM_USAGE_ULTRASONIC, OHOS::AudioStandard::STREAM_USAGE_VIDEO_COMMUNICATION + }; + std::vector systemUsages = { OHOS::AudioStandard::STREAM_USAGE_VOICE_CALL_ASSISTANT }; + usages.insert(usages.end(), systemUsages.begin(), systemUsages.end()); + + usage = src.usage.get_value(); + rendererFlags = src.rendererFlags; + if (src.volumeMode.has_value()) { + volumeMode = src.volumeMode.value(); + } + + if (std::find(systemUsages.begin(), systemUsages.end(), usage) != systemUsages.end() && !IsSystemApp()) { + MEDIA_LOGI("The caller is not a system app, usage = %{public}d", usage); + return false; + } + if (std::find(contents.begin(), contents.end(), content) == contents.end() || + std::find(usages.begin(), usages.end(), usage) == usages.end()) { + return false; + } + + if (audioRendererInfo.contentType != content || + audioRendererInfo.streamUsage != usage) { + audioEffectMode_ = OHOS::AudioStandard::AudioEffectMode::EFFECT_DEFAULT; + } + + audioRendererInfo = OHOS::AudioStandard::AudioRendererInfo { + static_cast< OHOS::AudioStandard::ContentType>(content), + static_cast< OHOS::AudioStandard::StreamUsage>(usage), rendererFlags, + static_cast< OHOS::AudioStandard::AudioVolumeMode>(volumeMode) + }; + return true; +} + +void AVPlayerImpl::SetAudioRendererInfo(optional_view audioRendererInfo) +{ + MediaTrace trace("AVPlayerImpl::set audioRendererInfo"); + MEDIA_LOGI("TaiheSetAudioRendererInfo In"); + + if (GetCurrentState() != AVPlayerState::STATE_INITIALIZED) { + OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "current state is not initialized, unsupport to set audio renderer info"); + return; + } + + if (audioRendererInfo.has_value()) { + if (!HandleParameter(audioRendererInfo.value(), audioRendererInfo_)) { + set_business_error(MSERR_EXT_API9_INVALID_PARAMETER, + "invalid parameters, please check the input audio renderer info"); + return; + } + auto task = std::make_shared>([this]() { + MEDIA_LOGI("SetAudioRendererInfo Task"); + if (player_ != nullptr) { + Format format; + (void)format.PutIntValue(PlayerKeys::CONTENT_TYPE, audioRendererInfo_.contentType); + (void)format.PutIntValue(PlayerKeys::STREAM_USAGE, audioRendererInfo_.streamUsage); + (void)format.PutIntValue(PlayerKeys::RENDERER_FLAG, audioRendererInfo_.rendererFlags); + (void)format.PutIntValue(PlayerKeys::VOLUME_MODE, audioRendererInfo_.volumeMode); + (void)player_->SetParameter(format); + } + }); + (void)taskQue_->EnqueueTask(task); + } else { + set_business_error(MSERR_EXT_API9_INVALID_PARAMETER, + "invalid parameters, please check the input"); + } + MEDIA_LOGI("SetAudioRendererInfo Out"); +} + +optional<::ohos::multimedia::audio::InterruptMode> AVPlayerImpl::GetAudioInterruptMode() +{ + MediaTrace trace("AVPlayerImpl::get audioInterruptMode"); + MEDIA_LOGI("TaiheGetAudioInterruptMode In"); + ohos::multimedia::audio::InterruptMode::key_t interruptModeKey; + MediaTaiheUtils::GetEnumKeyByValue(interruptMode_, interruptModeKey); + ::ohos::multimedia::audio::InterruptMode changeReason = + static_cast<::ohos::multimedia::audio::InterruptMode>(interruptModeKey); + ::ohos::multimedia::audio::InterruptMode interruptMode = { + changeReason, + }; + + return optional(std::in_place_t{}, interruptMode); +} + +void AVPlayerImpl::SetAudioInterruptMode(::ohos::multimedia::audio::InterruptMode audioInterruptMode) +{ + MediaTrace trace("AVPlayerImpl::set audioInterruptMode"); + MEDIA_LOGI("TaiheSetAudioInterruptMode In"); + if (!IsControllable()) { + OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, + "current state is not prepared/playing/paused/completed, unsupport audio interrupt operation"); + return; + } + int32_t interruptMode = audioInterruptMode; + if (interruptMode < OHOS::AudioStandard::InterruptMode::SHARE_MODE || + interruptMode > OHOS::AudioStandard::InterruptMode::INDEPENDENT_MODE) { + OnErrorCb(MSERR_EXT_API9_INVALID_PARAMETER, + "invalid parameters, please check the input interrupt Mode"); + return; + } + interruptMode_ = static_cast(interruptMode); + auto task = std::make_shared>([this]() { + if (player_ != nullptr) { + Format format; + (void)format.PutIntValue(PlayerKeys::AUDIO_INTERRUPT_MODE, interruptMode_); + (void)player_->SetParameter(format); + } + }); + (void)taskQue_->EnqueueTask(task); + MEDIA_LOGI("TaiheSetAudioInterruptMode Out"); +} + optional AVPlayerImpl::GetDataSrc() { MediaTrace trace("AVPlayerImpl::getDataSrc"); @@ -423,8 +636,8 @@ optional AVPlayerImpl::GetFdSrc() ohos::multimedia::media::AVFileDescriptor fdSrc; fdSrc.fd = fileDescriptor_.fd; - fdSrc.offset = optional(std::in_place_t{}, fileDescriptor_.offset); - fdSrc.length = optional(std::in_place_t{}, fileDescriptor_.length); + fdSrc.offset = optional(std::in_place_t{}, fileDescriptor_.offset); + fdSrc.length = optional(std::in_place_t{}, fileDescriptor_.length); MEDIA_LOGI("TaiheGetAVFileDescriptor Out"); return optional(std::in_place_t{}, fdSrc); } @@ -547,7 +760,7 @@ void AVPlayerImpl::SeekEnqueueTask(AVPlayerImpl *taihePlayer, int32_t time, int3 MEDIA_LOGI("0x%{public}06" PRIXPTR " TaiheSeek Out", FAKE_POINTER(taihePlayer)); } -void AVPlayerImpl::Seek(double timeMs, optional_view mode) +void AVPlayerImpl::Seek(int32_t timeMs, optional_view mode) { MediaTrace trace("AVPlayerImpl::seek"); MEDIA_LOGI("TaiheSeek in"); @@ -721,7 +934,7 @@ std::shared_ptr> AVPlayerImpl::StopTask() return task; } -std::shared_ptr AVPlayerImpl::GetAVMediaSource(weak::MediaSource src, +std::shared_ptr AVPlayerImpl::GetAVMediaSource(ohos::multimedia::media::weak::MediaSource src, std::shared_ptr &srcTmp) { std::shared_ptr mediaSource = std::make_shared(srcTmp->url, srcTmp->header); @@ -795,9 +1008,11 @@ void AVPlayerImpl::GetPlayStrategy(AVPlayStrategyTmp &playStrategy, PlaybackStra } if (strategy.preferredBufferDurationForPlaying.has_value()) { playStrategy.preferredBufferDurationForPlaying = strategy.preferredBufferDurationForPlaying.value(); + playStrategy.isSetBufferDurationForPlaying = true; } if (strategy.thresholdForAutoQuickPlay.has_value()) { playStrategy.thresholdForAutoQuickPlay = strategy.thresholdForAutoQuickPlay.value(); + playStrategy.isSetThresholdForAutoQuickPlay = true; } } @@ -812,7 +1027,8 @@ void AVPlayerImpl::EnqueueMediaSourceTask(const std::shared_ptr & (void)taskQue_->EnqueueTask(task); } -void AVPlayerImpl::SetMediaSourceSync(weak::MediaSource src, optional_view strategy) +void AVPlayerImpl::SetMediaSourceSync(ohos::multimedia::media::weak::MediaSource src, + optional_view strategy) { MediaTrace trace("AVPlayerImpl::setMediaSource"); MEDIA_LOGI("SetMediaSourceSync In"); @@ -848,7 +1064,7 @@ void AVPlayerImpl::SetMediaSourceSync(weak::MediaSource src, optional_view offset, optional_view length) +void AVPlayerImpl::AddSubtitleFromFdSync(int32_t fd, optional_view offset, optional_view length) { MEDIA_LOGI("AddSubtitleAVFileDescriptor In"); int64_t offsetLocal = -1; @@ -935,7 +1151,7 @@ map AVPlayerImpl::GetPlaybackInfoSync() return MediaTaiheUtils::CreateFormatBufferByRef(playbackInfo); } -void AVPlayerImpl::DeselectTrackSync(double index) +void AVPlayerImpl::DeselectTrackSync(int32_t index) { MediaTrace trace("AVPlayerImpl::deselectTrack"); MEDIA_LOGI("deselectTrack In"); @@ -959,7 +1175,7 @@ void AVPlayerImpl::DeselectTrackSync(double index) MEDIA_LOGI("deselectTrack Out"); } -void AVPlayerImpl::SelectTrackSync(double index, optional_view mode) +void AVPlayerImpl::SelectTrackSync(int32_t index, optional_view mode) { MediaTrace trace("AVPlayerImpl::selectTrack"); MEDIA_LOGI("SelectTrack In"); @@ -968,7 +1184,7 @@ void AVPlayerImpl::SelectTrackSync(double index, optional_view mode) "current state is not prepared/playing/paused/completed, unsupport selectTrack operation"); return; } - + HandleSelectTrack(index, mode); auto task = std::make_shared>([this, index = index_, mode = mode_]() { @@ -1024,7 +1240,7 @@ PlayerSwitchMode AVPlayerImpl::TransferSwitchMode(int32_t mode) return switchMode; } -array AVPlayerImpl::GetSelectedTracksSync() +array AVPlayerImpl::GetSelectedTracksSync() { MediaTrace trace("AVPlayerImpl::get selected tracks"); MEDIA_LOGI("TaiheGetSelectedTracks In"); @@ -1052,10 +1268,10 @@ array AVPlayerImpl::GetSelectedTracksSync() "current state unsupport get current selections"); } MEDIA_LOGI("TaiheGetSelectedTracks Out"); - return array(copy_data_t{}, trackIndex.data(), trackIndex.size()); + return array(copy_data_t{}, trackIndex.data(), trackIndex.size()); } -void AVPlayerImpl::SetVideoWindowSizeSync(double width, double height) +void AVPlayerImpl::SetVideoWindowSizeSync(int32_t width, int32_t height) { MediaTrace trace("AVPlayerImpl::setVideoWindowSize"); MEDIA_LOGI("TaiheSetVideoWindowSize In"); @@ -1142,7 +1358,7 @@ std::shared_ptr> AVPlayerImpl::SetSuperResolutionTask(bool return task; } -double AVPlayerImpl::GetPlaybackPosition() +int32_t AVPlayerImpl::GetPlaybackPosition() { MediaTrace trace("AVPlayerImpl::get playbackPosition"); MEDIA_LOGD("getPlaybackPosition In"); @@ -1165,7 +1381,7 @@ double AVPlayerImpl::GetPlaybackPosition() return playbackPosition; } -void AVPlayerImpl::SetBitrate(double bitrate) +void AVPlayerImpl::SetBitrate(int32_t bitrate) { MediaTrace trace("AVPlayerImpl::setBitrate"); MEDIA_LOGI("SelectBitrate In"); @@ -1190,7 +1406,7 @@ void AVPlayerImpl::SetBitrate(double bitrate) MEDIA_LOGI("0x%{public}06" PRIXPTR " SelectBitrate Out", FAKE_POINTER(this)); } -void AVPlayerImpl::SetPlaybackRangeSync(double startTimeMs, double endTimeMs, +void AVPlayerImpl::SetPlaybackRangeSync(int32_t startTimeMs, int32_t endTimeMs, optional_view<::ohos::multimedia::media::SeekMode> mode) { MediaTrace trace("AVPlayerImpl::setPlaybackRange"); @@ -1217,6 +1433,57 @@ void AVPlayerImpl::SetPlaybackRangeSync(double startTimeMs, double endTimeMs, MEDIA_LOGI("0x%{public}06" PRIXPTR " taiheSetPlaybackRange Out", FAKE_POINTER(this)); } +#ifdef SUPPORT_AVPLAYER_DRM +void AVPlayerImpl::SetDecryptionConfig(ohos::multimedia::drm::weak::MediaKeySession mediaKeySession, + bool secureVideoPath) +{ + MediaTrace trace("AVPlayerImpl::SetDecryptionConfig"); + MEDIA_LOGI("SetDecryptionConfig In"); + OHOS::DrmStandard::MediaKeySessionImpl* keySessionImpl = + reinterpret_cast(mediaKeySession->GetMediaKeySessionNative()); + if (keySessionImpl != nullptr) { + OHOS::sptr keySessionServiceProxy = + keySessionImpl->GetMediaKeySessionServiceProxy(); + MEDIA_LOGD("And it's count is: %{public}d", keySessionServiceProxy->GetSptrRefCount()); + { + std::lock_guard lock(syncMutex_); + CHECK_AND_RETURN_LOG((player_ != nullptr), "SetDecryptConfig player_ nullptr"); + (void)player_->SetDecryptConfig(keySessionServiceProxy, secureVideoPath); + } + } else { + MEDIA_LOGE("SetDecryptConfig keySessionImpl is nullptr!"); + } +} +#else +void AVPlayerImpl::SetDecryptionConfig(weak::MediaKeySession mediaKeySession, bool secureVideoPath) +{ + MEDIA_LOGI("SetDecryptConfig is not surpport."); + (void)mediaKeySession; + (void)secureVideoPath; + return nullptr; +} +#endif + +array AVPlayerImpl::GetMediaKeySystemInfos() +{ + MediaTrace trace("AVPlayerImpl::GetMediaKeySystemInfos"); + std::vector infoArray; + + MEDIA_LOGI("GetMediaKeySystemInfos In"); + + CHECK_AND_RETURN_RET_LOG(!localDrmInfos_.empty(), array(copy_data_t{}, + infoArray.data(), infoArray.size()), "localDrmInfo is empty"); + + for (auto item : localDrmInfos_) { + MediaKeySystemInfo info{ + item.first, + array(copy_data_t{}, item.second.data(), item.second.size()) + }; + infoArray.push_back(info); + } + return array(copy_data_t{}, infoArray.data(), infoArray.size()); +} + std::shared_ptr> AVPlayerImpl::EqueueSetPlayRangeTask(int32_t start, int32_t end, int32_t mode) { auto task = std::make_shared>([this, start, end, mode]() { @@ -1773,6 +2040,26 @@ void AVPlayerImpl::OnError(callback_view callback) return; } +void AVPlayerImpl::OnMediaKeySystemInfoUpdate(callback_view data)> callback) +{ + MediaTrace trace("AVPlayerImpl::OnMediaKeySystemInfoUpdate"); + MEDIA_LOGD("TaiheOnMediaKeySystemInfoUpdate In"); + + if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { + OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is released, unsupport to on event"); + return; + } + ani_env *env = taihe::get_env(); + std::shared_ptr data)>> taiheCallback = + std::make_shared data)>>(callback); + std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); + std::shared_ptr autoRef = std::make_shared(env, cacheCallback); + SaveCallbackReference(AVPlayerEvent::EVENT_DRM_INFO_UPDATE, autoRef); + MEDIA_LOGI("0x%{public}06" PRIXPTR + " TaiheOnMediaKeySystemInfoUpdate callbackName: mediaKeySystemInfoUpdate success", FAKE_POINTER(this)); + return; +} + void AVPlayerImpl::OnStateChange(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnStateChange"); @@ -1791,24 +2078,43 @@ void AVPlayerImpl::OnStateChange(callback_view callback) +void AVPlayerImpl::OnAudioInterrupt(callback_view callback) { - MediaTrace trace("AVPlayerImpl::OnMediaKeySystemInfoUpdate"); - MEDIA_LOGD("OnMediaKeySystemInfoUpdate In"); + MediaTrace trace("AVPlayerImpl::OnAudioInterrupt"); + MEDIA_LOGD("TaiheOnAudioInterrupt In"); if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is released, unsupport to on event"); return; } + ani_env *env = taihe::get_env(); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); + std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); + std::shared_ptr autoRef = std::make_shared(env, cacheCallback); + SaveCallbackReference(AVPlayerEvent::EVENT_AUDIO_INTERRUPT, autoRef); + MEDIA_LOGI("0x%{public}06" PRIXPTR " TaiheOnAudioInterrupt callbackName: audioInterrupt success", + FAKE_POINTER(this)); + return; +} +void AVPlayerImpl::OnAudioOutputDeviceChangeWithInfo(callback_view callback) +{ + MediaTrace trace("AVPlayerImpl::OnAudioOutputDeviceChangeWithInfo"); + MEDIA_LOGD("TaiheOnAudioOutputDeviceChangeWithInfo In"); + if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { + OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is released, unsupport to on event"); + return; + } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); - SaveCallbackReference(AVPlayerEvent::EVENT_DRM_INFO_UPDATE, autoRef); + SaveCallbackReference(AVPlayerEvent::EVENT_AUDIO_DEVICE_CHANGE, autoRef); MEDIA_LOGI("0x%{public}06" PRIXPTR - " TaiheOnMediaKeySystemInfoUpdate callbackName: mediaKeySystemInfoUpdate success", FAKE_POINTER(this)); + " TaiheOnAudioOutputDeviceChangeWithInfo callbackName: audioOutputDeviceChange success", FAKE_POINTER(this)); return; } @@ -1850,7 +2156,7 @@ void AVPlayerImpl::OnStartRenderFrame(callback_view callback) return; } -void AVPlayerImpl::OnSeekDone(callback_view callback) +void AVPlayerImpl::OnSeekDone(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnSeekDone"); MEDIA_LOGD("TaiheOnSeekDone In"); @@ -1860,8 +2166,8 @@ void AVPlayerImpl::OnSeekDone(callback_view callback) return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_SEEK_DONE, autoRef); @@ -1869,7 +2175,7 @@ void AVPlayerImpl::OnSeekDone(callback_view callback) return; } -void AVPlayerImpl::OnDurationUpdate(callback_view callback) +void AVPlayerImpl::OnDurationUpdate(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnDurationUpdate"); MEDIA_LOGD("TaiheOnDurationUpdate In"); @@ -1879,8 +2185,8 @@ void AVPlayerImpl::OnDurationUpdate(callback_view callback) return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_DURATION_UPDATE, autoRef); @@ -1889,7 +2195,7 @@ void AVPlayerImpl::OnDurationUpdate(callback_view callback) return; } -void AVPlayerImpl::OnTimeUpdate(callback_view callback) +void AVPlayerImpl::OnTimeUpdate(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnTimeUpdate"); MEDIA_LOGD("TaiheOnTimeUpdate In"); @@ -1899,8 +2205,8 @@ void AVPlayerImpl::OnTimeUpdate(callback_view callback) return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_TIME_UPDATE, autoRef); @@ -1927,7 +2233,7 @@ void AVPlayerImpl::OnVolumeChange(callback_view callback) return; } -void AVPlayerImpl::OnSpeedDone(callback_view callback) +void AVPlayerImpl::OnSpeedDone(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnSpeedDone"); MEDIA_LOGD("TaiheOnSpeedDone In"); @@ -1937,8 +2243,8 @@ void AVPlayerImpl::OnSpeedDone(callback_view callback) return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_SPEED_DONE, autoRef); @@ -1946,7 +2252,7 @@ void AVPlayerImpl::OnSpeedDone(callback_view callback) return; } -void AVPlayerImpl::OnBitrateDone(callback_view callback) +void AVPlayerImpl::OnBitrateDone(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnBitrateDone"); MEDIA_LOGD("TaiheOnBitrateDone In"); @@ -1956,8 +2262,8 @@ void AVPlayerImpl::OnBitrateDone(callback_view callback) return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_BITRATE_DONE, autoRef); @@ -1965,7 +2271,7 @@ void AVPlayerImpl::OnBitrateDone(callback_view callback) return; } -void AVPlayerImpl::OnAvailableBitrates(callback_view)> callback) +void AVPlayerImpl::OnAvailableBitrates(callback_view)> callback) { MediaTrace trace("AVPlayerImpl::OnBitrateDone"); MEDIA_LOGD("TaiheOnBitrateDone In"); @@ -1975,8 +2281,8 @@ void AVPlayerImpl::OnAvailableBitrates(callback_view)> c return; } ani_env *env = taihe::get_env(); - std::shared_ptr)>> taiheCallback = - std::make_shared)>>(callback); + std::shared_ptr)>> taiheCallback = + std::make_shared)>>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_AVAILABLE_BITRATES, autoRef); @@ -1993,6 +2299,10 @@ void AVPlayerImpl::OnAmplitudeUpdate(callback_view)> cal OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is released, unsupport to on event"); return; } + calMaxAmplitude_ = true; + if (player_ != nullptr) { + (void)player_->SetMaxAmplitudeCbStatus(calMaxAmplitude_); + } ani_env *env = taihe::get_env(); std::shared_ptr)>> taiheCallback = std::make_shared)>>(callback); @@ -2004,14 +2314,18 @@ void AVPlayerImpl::OnAmplitudeUpdate(callback_view)> cal return; } -void AVPlayerImpl::OnBufferingUpdate(callback_view callback) +void AVPlayerImpl::OnBufferingUpdate(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnBufferingUpdate"); MEDIA_LOGD("TaiheOnBufferingUpdate In"); + if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { + OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is released, unsupport to on event"); + return; + } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_BUFFERING_UPDATE, autoRef); @@ -2020,7 +2334,7 @@ void AVPlayerImpl::OnBufferingUpdate(callback_view callback) +void AVPlayerImpl::OnVideoSizeChange(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnVideoSizeChange"); MEDIA_LOGD("TaiheOnVideoSizeChange In"); @@ -2030,8 +2344,8 @@ void AVPlayerImpl::OnVideoSizeChange(callback_view callbac return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_VIDEO_SIZE_CHANGE, autoRef); @@ -2040,7 +2354,7 @@ void AVPlayerImpl::OnVideoSizeChange(callback_view callbac return; } -void AVPlayerImpl::OnTrackChange(callback_view callback) +void AVPlayerImpl::OnTrackChange(callback_view callback) { MediaTrace trace("AVPlayerImpl::OnTrackChange"); MEDIA_LOGD("TaiheOnTrackChange In"); @@ -2050,8 +2364,8 @@ void AVPlayerImpl::OnTrackChange(callback_view callback) return; } ani_env *env = taihe::get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_TRACKCHANGE, autoRef); @@ -2064,6 +2378,10 @@ void AVPlayerImpl::OnSubtitleUpdate(callback_view> taiheCallback = std::make_shared>(callback); @@ -2116,8 +2434,8 @@ void AVPlayerImpl::OnTrackInfoUpdate(callback_view payloadTypes, - callback_view, optional_view)> callback) +void AVPlayerImpl::OnSeiMessageReceived(array_view payloadTypes, + callback_view, optional_view)> callback) { MediaTrace trace("AVPlayerImpl::OnSeiMessageReceived"); MEDIA_LOGD("TaiheOnSeiMessageReceived In"); @@ -2126,9 +2444,9 @@ void AVPlayerImpl::OnSeiMessageReceived(array_view payloadTypes, OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is released, unsupport to on event"); return; } - bool seiMessageCallbackflag_ = true; + seiMessageCallbackflag_ = true; - if (player_ != nullptr && seiMessageCallbackflag_) { + if (player_ != nullptr) { MEDIA_LOGI("seiMessageCallbackflag_ = %{public}d", seiMessageCallbackflag_); std::vector payloadTypesInt; payloadTypesInt.reserve(payloadTypes.size()); @@ -2138,8 +2456,8 @@ void AVPlayerImpl::OnSeiMessageReceived(array_view payloadTypes, player_->SetSeiMessageCbStatus(seiMessageCallbackflag_, payloadTypesInt); } ani_env *env = taihe::get_env(); - std::shared_ptr, optional_view)>> taiheCallback = - std::make_shared, optional_view)>>(callback); + std::shared_ptr, optional_view)>> taiheCallback = + std::make_shared, optional_view)>>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); SaveCallbackReference(AVPlayerEvent::EVENT_SEI_MESSAGE_INFO, autoRef); @@ -2162,6 +2480,22 @@ void AVPlayerImpl::OffError(optional_view> callback) MEDIA_LOGI("OffError End"); } +void AVPlayerImpl::OffMediaKeySystemInfoUpdate(optional_view data)>> callback) +{ + MediaTrace trace("AVPlayerImpl::OffMediaKeySystemInfoUpdate"); + MEDIA_LOGD("OffMediaKeySystemInfoUpdate In"); + + if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { + return; + } + + std::string callbackName = "mediaKeySystemInfoUpdate"; + MaxAmplitudeCallbackOff(callbackName); + ClearCallbackReference(callbackName); + MEDIA_LOGI("OffMediaKeySystemInfoUpdate End"); +} + void AVPlayerImpl::OffStateChange(optional_view> callback) { @@ -2178,19 +2512,36 @@ void AVPlayerImpl::OffStateChange(optional_view> callback) +void AVPlayerImpl::OffAudioInterrupt(optional_view> callback) { - MediaTrace trace("AVPlayerImpl::OffMediaKeySystemInfoUpdate"); - MEDIA_LOGD("OffMediaKeySystemInfoUpdate In"); + MediaTrace trace("AVPlayerImpl::OffAudioInterrupt"); + MEDIA_LOGD("OffAudioInterrupt In"); if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { return; } - std::string callbackName = "mediaKeySystemInfoUpdate"; + std::string callbackName = "audioInterrupt"; MaxAmplitudeCallbackOff(callbackName); ClearCallbackReference(callbackName); - MEDIA_LOGI("OffMediaKeySystemInfoUpdate End"); + MEDIA_LOGI("OffAudioInterrupt End"); +} + +void AVPlayerImpl::OffAudioOutputDeviceChangeWithInfo(::taihe::optional_view<::taihe::callback> callback) +{ + MediaTrace trace("AVPlayerImpl::OffAudioOutputDeviceChangeWithInfo"); + MEDIA_LOGD("OffAudioOutputDeviceChangeWithInfo In"); + + if (GetCurrentState() == AVPlayerState::STATE_RELEASED) { + return; + } + + std::string callbackName = "audioOutputDeviceChange"; + MaxAmplitudeCallbackOff(callbackName); + ClearCallbackReference(callbackName); + MEDIA_LOGI("OffAudioOutputDeviceChangeWithInfo End"); } void AVPlayerImpl::OffEndOfStream(optional_view> callback) @@ -2221,7 +2572,7 @@ void AVPlayerImpl::OffStartRenderFrame(optional_view> ClearCallbackReference(callbackName); MEDIA_LOGI("OffStartRenderFrame End"); } -void AVPlayerImpl::OffSeekDone(optional_view> callback) +void AVPlayerImpl::OffSeekDone(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffSeekDone"); MEDIA_LOGD("OffSeekDone In"); @@ -2235,7 +2586,7 @@ void AVPlayerImpl::OffSeekDone(optional_view> callback) ClearCallbackReference(callbackName); MEDIA_LOGI("OffSeekDone End"); } -void AVPlayerImpl::OffDurationUpdate(optional_view> callback) +void AVPlayerImpl::OffDurationUpdate(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffDurationUpdate"); MEDIA_LOGD("OffDurationUpdate In"); @@ -2249,7 +2600,7 @@ void AVPlayerImpl::OffDurationUpdate(optional_view> callb ClearCallbackReference(callbackName); MEDIA_LOGI("OffDurationUpdate End"); } -void AVPlayerImpl::OffTimeUpdate(optional_view> callback) +void AVPlayerImpl::OffTimeUpdate(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffTimeUpdate"); MEDIA_LOGD("OffTimeUpdate In"); @@ -2277,7 +2628,7 @@ void AVPlayerImpl::OffVolumeChange(optional_view> callbac ClearCallbackReference(callbackName); MEDIA_LOGI("OffVolumeChange End"); } -void AVPlayerImpl::OffSpeedDone(optional_view> callback) +void AVPlayerImpl::OffSpeedDone(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffSpeedDone"); MEDIA_LOGD("OffSpeedDone In"); @@ -2291,7 +2642,7 @@ void AVPlayerImpl::OffSpeedDone(optional_view> callback) ClearCallbackReference(callbackName); MEDIA_LOGI("OffSpeedDone End"); } -void AVPlayerImpl::OffBitrateDone(optional_view> callback) +void AVPlayerImpl::OffBitrateDone(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffBitrateDone"); MEDIA_LOGD("OffBitrateDone In"); @@ -2305,7 +2656,7 @@ void AVPlayerImpl::OffBitrateDone(optional_view> callback ClearCallbackReference(callbackName); MEDIA_LOGI("OffBitrateDone End"); } -void AVPlayerImpl::OffAvailableBitrates(optional_view)>> callback) +void AVPlayerImpl::OffAvailableBitrates(optional_view)>> callback) { MediaTrace trace("AVPlayerImpl::OffAvailableBitrates"); MEDIA_LOGD("OffAvailableBitrates In"); @@ -2335,7 +2686,7 @@ void AVPlayerImpl::OffAmplitudeUpdate(optional_view> callback) + int32_t)>> callback) { MediaTrace trace("AVPlayerImpl::OffBufferingUpdate"); MEDIA_LOGD("OffBufferingUpdate In"); @@ -2349,7 +2700,7 @@ void AVPlayerImpl::OffBufferingUpdate(optional_view> callback) +void AVPlayerImpl::OffVideoSizeChange(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffVideoSizeChange"); MEDIA_LOGD("OffVideoSizeChange In"); @@ -2364,7 +2715,7 @@ void AVPlayerImpl::OffVideoSizeChange(optional_view> callback) +void AVPlayerImpl::OffTrackChange(optional_view> callback) { MediaTrace trace("AVPlayerImpl::OffTrackChange"); MEDIA_LOGD("OffTrackChange In"); @@ -2408,7 +2759,7 @@ void AVPlayerImpl::OffSuperResolutionChanged(optional_view> ClearCallbackReference(callbackName); MEDIA_LOGI("OffSuperResolutionChanged End"); } -void AVPlayerImpl::OffTrackInfoUpdate(optional_view>)>> callback) +void AVPlayerImpl::OffTrackInfoUpdate(optional_view>)>> callback) { MediaTrace trace("AVPlayerImpl::OffTrackInfoUpdate"); MEDIA_LOGD("OffTrackInfoUpdate In"); @@ -2423,9 +2774,9 @@ void AVPlayerImpl::OffTrackInfoUpdate(optional_view payloadTypes, +void AVPlayerImpl::OffSeiMessageReceived(array_view payloadTypes, optional_view, - optional_view)>> callback) + optional_view)>> callback) { MediaTrace trace("AVPlayerImpl::OffSeiMessageReceived"); MEDIA_LOGD("OffSeiMessageReceived In"); diff --git a/frameworks/taihe/media/src/avrecorder_callback_taihe.cpp b/frameworks/taihe/media/src/avrecorder_callback_taihe.cpp index 1add1fdc6..31ae3c774 100644 --- a/frameworks/taihe/media/src/avrecorder_callback_taihe.cpp +++ b/frameworks/taihe/media/src/avrecorder_callback_taihe.cpp @@ -18,6 +18,7 @@ #include "media_log.h" #include "avrecorder_callback_taihe.h" #include "media_taihe_utils.h" +#include "media_library_comm_ani.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_RECORDER, "AVRecorderCallback"}; @@ -27,6 +28,9 @@ using namespace OHOS::Media; namespace ANI { namespace Media { +#ifdef SUPPORT_RECORDER_CREATE_FILE +const int32_t CAMERA_SHOT_TYPE = 1; // CameraShotType VIDEO +#endif AVRecorderCallback::AVRecorderCallback() { MEDIA_LOGI("0x%{public}06" PRIXPTR "Instances create", FAKE_POINTER(this)); @@ -120,6 +124,86 @@ void AVRecorderCallback::OnTaiheStateCallBack(AVRecordTaiheCallback *taiheCb) co } } +#ifdef SUPPORT_RECORDER_CREATE_FILE +void AVRecorderCallback::OnTaihePhotoAssertAvailableCallback(AVRecordTaiheCallback *taiheCb) const +{ + auto task = [event = taiheCb]() { + do { + std::string request = event->callbackName; + std::shared_ptr ref = event->autoRef.lock(); + CHECK_AND_RETURN_LOG(ref != nullptr, "ref is nullptr"); + auto func = ref->callbackRef_; + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + ani_object aniObject = MediaLibraryCommAni::CreatePhotoAssetAni( + taihe::get_env(), event->uri, CAMERA_SHOT_TYPE); + uintptr_t photoAssetPtr = reinterpret_cast(&aniObject); + (*cacheCallback)(photoAssetPtr); + } while (0); + delete event; + }; + mainHandler_->PostTask(task, "OnPhotoAssetAvailable", 0, OHOS::AppExecFwk::EventQueue::Priority::IMMEDIATE, {}); +} +#endif + +void AVRecorderCallback::OnTaiheAudioCaptureChangeCallback(AVRecordTaiheCallback *taiheCb) const +{ + MEDIA_LOGI("AVRecorderCallback OnTaiheAudioCaptureChangeCallback is start"); + auto task = [this, event = taiheCb]() { + std::string request = event->callbackName; + do { + MEDIA_LOGD("OnTaiheAudioCaptureChangeCallback is called"); + std::shared_ptr errorRef = event->autoRef.lock(); + CHECK_AND_RETURN_LOG(errorRef != nullptr, "ref is nullptr"); + auto func = errorRef->callbackRef_; + + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + (*cacheCallback)(this->GetAudioCapturerChangeInfo(event)); + } while (0); + delete event; + }; + mainHandler_->PostTask(task, "OnAudioCapturerChange", 0, OHOS::AppExecFwk::EventQueue::Priority::IMMEDIATE, {}); +} + +void AVRecorderCallback::SendAudioCaptureChangeCallback(const OHOS::Media::AudioRecorderChangeInfo + &audioRecorderChangeInfo) +{ + MEDIA_LOGI("AVRecorderCallback SendAudioCaptureChangeCallback is start"); + std::lock_guard lock(mutex_); + if (refMap_.find(AVRecorderEvent::EVENT_AUDIO_CAPTURE_CHANGE) == refMap_.end()) { + MEDIA_LOGW("can not find audioCaptureChange callback"); + return; + } + + AVRecordTaiheCallback *cb = new(std::nothrow) AVRecordTaiheCallback(); + CHECK_AND_RETURN_LOG(cb != nullptr, "cb is nullptr"); + cb->autoRef = refMap_.at(AVRecorderEvent::EVENT_AUDIO_CAPTURE_CHANGE); + cb->callbackName = AVRecorderEvent::EVENT_AUDIO_CAPTURE_CHANGE; + cb->audioRecorderChangeInfo = audioRecorderChangeInfo; + OnTaiheAudioCaptureChangeCallback(cb); +} + +void AVRecorderCallback::SendPhotoAssertAvailableCallback(const std::string &uri) +{ + std::lock_guard lock(mutex_); + if (refMap_.find(AVRecorderEvent::EVENT_PHOTO_ASSET_AVAILABLE) == refMap_.end()) { + MEDIA_LOGW("can not find PhotoAssertAvailable callback"); + return; + } + + AVRecordTaiheCallback *cb = new(std::nothrow) AVRecordTaiheCallback(); + CHECK_AND_RETURN_LOG(cb != nullptr, "cb is nullptr"); + cb->autoRef = refMap_.at(AVRecorderEvent::EVENT_PHOTO_ASSET_AVAILABLE); + cb->callbackName = AVRecorderEvent::EVENT_PHOTO_ASSET_AVAILABLE; + cb->uri = uri; +#ifdef SUPPORT_RECORDER_CREATE_FILE + OnTaihePhotoAssertAvailableCallback(cb); +#endif +} + void AVRecorderCallback::SaveCallbackReference(const std::string &name, std::weak_ptr ref) { std::lock_guard lock(mutex_); @@ -183,5 +267,95 @@ void AVRecorderCallback::OnInfo(int32_t type, int32_t extra) SendStateCallback(AVRecorderState::STATE_STOPPED, OHOS::Media::StateChangeReason::BACKGROUND); } } + +void AVRecorderCallback::OnAudioCaptureChange(const OHOS::Media::AudioRecorderChangeInfo &audioRecorderChangeInfo) +{ + MEDIA_LOGI("OnAudioCaptureChange() is called"); + MEDIA_LOGI("AVRecorderCallback OnAudioCaptureChange is start"); + SendAudioCaptureChangeCallback(audioRecorderChangeInfo); +} + +void AVRecorderCallback::OnPhotoAssertAvailable(const std::string &uri) +{ + MEDIA_LOGI("OnPhotoAssertAvailable() is called"); + SendPhotoAssertAvailableCallback(uri); +} + +::ohos::multimedia::audio::AudioCapturerChangeInfo AVRecorderCallback::GetAudioCapturerChangeInfo( + AVRecordTaiheCallback *taiheCb) const +{ + ohos::multimedia::audio::AudioState::key_t audioStateKey; + MediaTaiheUtils::GetEnumKeyByValue( + taiheCb->audioRecorderChangeInfo.capturerState, audioStateKey); + ohos::multimedia::audio::SourceType::key_t sourceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + taiheCb->audioRecorderChangeInfo.capturerInfo.sourceType, sourceTypeKey); + + ::ohos::multimedia::audio::AudioCapturerInfo audioCapturerInfo { + std::move(::ohos::multimedia::audio::SourceType(sourceTypeKey)), + taiheCb->audioRecorderChangeInfo.capturerInfo.capturerFlags + }; + + std::vector<::ohos::multimedia::audio::AudioDeviceDescriptor> audioDeviceDescriptor; + audioDeviceDescriptor.push_back(GetDeviceInfo(taiheCb)); + ::ohos::multimedia::audio::AudioCapturerChangeInfo audioCapturerChangeInfo { + std::move(taiheCb->audioRecorderChangeInfo.sessionId), std::move(taiheCb->audioRecorderChangeInfo.clientUID), + std::move(audioCapturerInfo), + std::move(::ohos::multimedia::audio::AudioState(audioStateKey)), + array<::ohos::multimedia::audio::AudioDeviceDescriptor>(audioDeviceDescriptor), + optional(std::in_place_t{}, taiheCb->audioRecorderChangeInfo.muted) + }; + return audioCapturerChangeInfo; +} + +::ohos::multimedia::audio::AudioDeviceDescriptor AVRecorderCallback::GetDeviceInfo( + AVRecordTaiheCallback *taiheCb) const +{ + ohos::multimedia::audio::DeviceRole::key_t deviceRoleKey; + MediaTaiheUtils::GetEnumKeyByValue( + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.deviceRole, deviceRoleKey); + ohos::multimedia::audio::DeviceType::key_t deviceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.deviceType, deviceTypeKey); + taihe::string name = MediaTaiheUtils::ToTaiheString(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.deviceName); + taihe::string address = + MediaTaiheUtils::ToTaiheString(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.macAddress); + std::vector samplingRateVec( + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.audioStreamInfo.samplingRate.begin(), + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.audioStreamInfo.samplingRate.end()); + std::vector channelsVec(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.audioStreamInfo.channels.begin(), + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.audioStreamInfo.channels.end()); + taihe::string networkId = + MediaTaiheUtils::ToTaiheString(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.networkId); + taihe::string displayName = MediaTaiheUtils::ToTaiheString( + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.displayName); + ohos::multimedia::audio::AudioEncodingType::key_t audioEncodingTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + taiheCb->audioRecorderChangeInfo.inputDeviceInfo.audioStreamInfo.encoding, audioEncodingTypeKey); + std::vector channelMasks; + channelMasks.push_back(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.channelMasks); + std::vector<::ohos::multimedia::audio::AudioEncodingType> audioEncodingType; + audioEncodingType.push_back(audioEncodingTypeKey); + + ::ohos::multimedia::audio::AudioDeviceDescriptor descriptor { + std::move(::ohos::multimedia::audio::DeviceRole(deviceRoleKey)), + std::move(::ohos::multimedia::audio::DeviceType(deviceTypeKey)), + std::move(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.deviceId), + std::move(name), + std::move(address), + array(samplingRateVec), + array(channelsVec), + array(channelMasks), + std::move(networkId), + std::move(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.interruptGroupId), + std::move(taiheCb->audioRecorderChangeInfo.inputDeviceInfo.volumeGroupId), + std::move(displayName), + optional<::taihe::array<::ohos::multimedia::audio::AudioEncodingType>>( + std::in_place_t{}, array<::ohos::multimedia::audio::AudioEncodingType>(audioEncodingType)), + optional(std::nullopt), + optional(std::nullopt), + }; + return descriptor; +} } } \ No newline at end of file diff --git a/frameworks/taihe/media/src/avrecorder_taihe.cpp b/frameworks/taihe/media/src/avrecorder_taihe.cpp index 3adb69e19..38ebd6c2b 100644 --- a/frameworks/taihe/media/src/avrecorder_taihe.cpp +++ b/frameworks/taihe/media/src/avrecorder_taihe.cpp @@ -21,6 +21,7 @@ #include "avcodec_info.h" #include "av_common.h" #include "media_taihe_utils.h" +#include "pixel_map_taihe.h" using namespace ANI::Media; using namespace ohos::multimedia::media; @@ -78,11 +79,11 @@ RetInfo GetRetInfo(int32_t errCode, const std::string &operate, const std::strin if (errCode == MSERR_UNSUPPORT_VID_PARAMS) { return RetInfo(err, "The video parameter is not supported. Please check the type and range."); } - + if (errCode == MSERR_UNSUPPORT_AUD_PARAMS) { return RetInfo(err, "The audio parameter is not supported. Please check the type and range."); } - + std::string message; if (err == MSERR_EXT_API9_INVALID_PARAMETER) { message = MSExtErrorAPI9ToString(err, param, "") + add; @@ -103,12 +104,12 @@ void SetRetInfoError(int32_t errCode, const std::string &operate, set_business_error(err, "The video parameter is not supported. Please check the type and range."); return; } - + if (errCode == MSERR_UNSUPPORT_AUD_PARAMS) { set_business_error(err, "The audio parameter is not supported. Please check the type and range."); return; } - + std::string message; if (err == MSERR_EXT_API9_INVALID_PARAMETER) { message = MSExtErrorAPI9ToString(err, param, "") + add; @@ -174,7 +175,7 @@ std::shared_ptr> AVRecorderImpl::GetPromiseTask(AVRecorderI auto memberFunc = itFunc->second; CHECK_AND_RETURN_RET_LOG(memberFunc != nullptr, ret, "memberFunc is nullptr!"); ret = (taihe->*memberFunc)(); - + MEDIA_LOGI("%{public}s End", option.c_str()); return ret; }); @@ -978,7 +979,7 @@ void AVRecorderImpl::SetAVRecorderConfig( optional<::taihe::array<::ohos::multimedia::media::MetaSourceType>>(std::nullopt), optional<::ohos::multimedia::media::FileGenerationMode>(std::nullopt), optional<::ohos::multimedia::media::AVMetadata>(std::nullopt), - optional(std::nullopt), + optional(std::nullopt), }; return config; } @@ -996,20 +997,20 @@ void AVRecorderImpl::SetAVRecorderConfig( MediaTaiheUtils::GetEnumKeyByStringValue( fileFormatValue, containerFormatTypeKey); ::ohos::multimedia::media::AVRecorderProfile aVRecorderProfile { - optional(std::nullopt), optional(std::nullopt), + optional(std::nullopt), optional(std::nullopt), optional<::ohos::multimedia::media::CodecMimeType>(std::nullopt), - optional(std::nullopt), + optional(std::nullopt), containerFormatTypeKey, - optional(std::nullopt), + optional(std::nullopt), optional<::ohos::multimedia::media::CodecMimeType>(std::nullopt), - optional(std::nullopt), optional(std::nullopt), - optional(std::nullopt), optional(std::nullopt), + optional(std::nullopt), optional(std::nullopt), + optional(std::nullopt), optional(std::nullopt), optional(std::nullopt), optional(std::nullopt), }; if (config->withAudio) { - aVRecorderProfile.audioBitrate = optional(std::in_place_t{}, config->profile.audioBitrate); - aVRecorderProfile.audioChannels = optional(std::in_place_t{}, config->profile.audioChannels); - aVRecorderProfile.audioSampleRate = optional(std::in_place_t{}, config->profile.audioSampleRate); + aVRecorderProfile.audioBitrate = optional(std::in_place_t{}, config->profile.audioBitrate); + aVRecorderProfile.audioChannels = optional(std::in_place_t{}, config->profile.audioChannels); + aVRecorderProfile.audioSampleRate = optional(std::in_place_t{}, config->profile.audioSampleRate); std::string audioCodec = ""; SetAudioCodecFormat(config->profile.audioCodecFormat, audioCodec); taihe::string audioValue = MediaTaiheUtils::ToTaiheString(audioCodec); @@ -1019,10 +1020,10 @@ void AVRecorderImpl::SetAVRecorderConfig( optional<::ohos::multimedia::media::CodecMimeType>(std::in_place_t{}, codecMimeTypeKey); } if (config->withVideo) { - aVRecorderProfile.videoBitrate = optional(std::in_place_t{}, config->profile.videoBitrate); - aVRecorderProfile.videoFrameWidth = optional(std::in_place_t{}, config->profile.videoFrameWidth); - aVRecorderProfile.videoFrameHeight = optional(std::in_place_t{}, config->profile.videoFrameHeight); - aVRecorderProfile.videoFrameRate = optional(std::in_place_t{}, config->profile.videoFrameRate); + aVRecorderProfile.videoBitrate = optional(std::in_place_t{}, config->profile.videoBitrate); + aVRecorderProfile.videoFrameWidth = optional(std::in_place_t{}, config->profile.videoFrameWidth); + aVRecorderProfile.videoFrameHeight = optional(std::in_place_t{}, config->profile.videoFrameHeight); + aVRecorderProfile.videoFrameRate = optional(std::in_place_t{}, config->profile.videoFrameRate); std::string videoCodec = ""; SetVideoCodecFormat(config->profile.videoCodecFormat, videoCodec); taihe::string videoValue = MediaTaiheUtils::ToTaiheString(videoCodec); @@ -1044,16 +1045,16 @@ void AVRecorderImpl::SetAVRecorderConfig( MediaTaiheUtils::GetEnumKeyByStringValue( value, containerFormatTypeKey); ::ohos::multimedia::media::AVRecorderProfile aVRecorderProfile { - optional(std::nullopt), - optional(std::nullopt), + optional(std::nullopt), + optional(std::nullopt), optional<::ohos::multimedia::media::CodecMimeType>(std::nullopt), - optional(std::nullopt), + optional(std::nullopt), containerFormatTypeKey, - optional(std::nullopt), + optional(std::nullopt), optional<::ohos::multimedia::media::CodecMimeType>(std::nullopt), - optional(std::nullopt), - optional(std::nullopt), - optional(std::nullopt), + optional(std::nullopt), + optional(std::nullopt), + optional(std::nullopt), optional(std::nullopt), optional(std::nullopt), optional(std::nullopt), @@ -1074,7 +1075,7 @@ std::shared_ptr> AVRecorderImpl::GetAVRecorderConfigTask( CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, GetRetInfo(MSERR_INVALID_OPERATION, option, "")); - + CHECK_AND_RETURN_RET(taihe->CheckRepeatOperation(option) == MSERR_OK, RetInfo(MSERR_EXT_API9_OK, "")); @@ -1183,7 +1184,7 @@ void AVRecorderImpl::GetAudioEncoderInfo(EncoderCapabilityData encoderCapData, optional<::ohos::multimedia::media::Range>(std::nullopt), optional<::ohos::multimedia::media::Range>(std::in_place_t{}, GetRange( encoderCapData.channels.minVal, encoderCapData.channels.maxVal)), - optional<::taihe::array>(std::in_place_t{}, array(copy_data_t{}, + optional<::taihe::array>(std::in_place_t{}, array(copy_data_t{}, encoderCapData.sampleRate.data(), encoderCapData.sampleRate.size())), }; TaiheEncoderInfos.push_back(TaiheEncoderInfo); @@ -1208,7 +1209,7 @@ void AVRecorderImpl::GetVideoEncoderInfo(EncoderCapabilityData encoderCapData, optional<::ohos::multimedia::media::Range>(std::in_place_t{}, GetRange( encoderCapData.height.minVal, encoderCapData.height.maxVal)), optional<::ohos::multimedia::media::Range>(std::nullopt), - optional<::taihe::array>(std::nullopt), + optional<::taihe::array>(std::nullopt), }; TaiheEncoderInfos.push_back(TaiheEncoderInfo); } @@ -1240,7 +1241,7 @@ std::shared_ptr> AVRecorderImpl::GetEncoderInfoTask( CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, GetRetInfo(MSERR_INVALID_OPERATION, option, "")); - + CHECK_AND_RETURN_RET(taihe->CheckRepeatOperation(option) == MSERR_OK, RetInfo(MSERR_EXT_API9_OK, "")); @@ -1333,7 +1334,7 @@ std::shared_ptr> AVRecorderImpl::GetInputMetaSurface( taihe->metaSurface_ = taihe->recorder_->GetMetaSurface(taihe->metaSourceIDMap_.at(type)); CHECK_AND_RETURN_RET_LOG(taihe->metaSurface_ != nullptr, GetRetInfo(MSERR_INVALID_OPERATION, "GetInputMetaSurface", ""), "failed to GetInputMetaSurface"); - + OHOS::SurfaceError error = OHOS::SurfaceUtils::GetInstance()->Add(taihe->metaSurface_->GetUniqueId(), taihe->metaSurface_); CHECK_AND_RETURN_RET_LOG(error == OHOS::SURFACE_ERROR_OK, @@ -1397,7 +1398,7 @@ std::shared_ptr> AVRecorderImpl::IsWatermarkSupportedTask( CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, GetRetInfo(MSERR_INVALID_OPERATION, option, "")); - + CHECK_AND_RETURN_RET(taihe->CheckRepeatOperation(option) == MSERR_OK, RetInfo(MSERR_EXT_API9_OK, "")); @@ -1415,7 +1416,7 @@ int32_t AVRecorderImpl::IsWatermarkSupported(bool &isWatermarkSupported) return recorder_->IsWatermarkSupported(isWatermarkSupported); } -void AVRecorderImpl::UpdateRotationSync(double rotation) +void AVRecorderImpl::UpdateRotationSync(int32_t rotation) { MediaTrace trace("AVRecorder::UpdateRotationSync"); const std::string &opt = AVRecordergOpt::SET_ORIENTATION_HINT; @@ -1478,15 +1479,15 @@ std::shared_ptr> AVRecorderImpl::GetSetOrientationHintTask( CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, GetRetInfo(MSERR_INVALID_OPERATION, option, "")); - + taihe->recorder_->SetOrientationHint(config->rotation); - + MEDIA_LOGI("%{public}s End", option.c_str()); return RetInfo(MSERR_EXT_API9_OK, ""); }); } -double AVRecorderImpl::GetAudioCapturerMaxAmplitudeSync() +int32_t AVRecorderImpl::GetAudioCapturerMaxAmplitudeSync() { MediaTrace trace("AVRecorder::GetAudioCapturerMaxAmplitudeSync"); const std::string &opt = AVRecordergOpt::GET_MAX_AMPLITUDE; @@ -1534,7 +1535,7 @@ std::shared_ptr> AVRecorderImpl::GetMaxAmplitudeTask( CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, GetRetInfo(MSERR_INVALID_OPERATION, option, "")); - + CHECK_AND_RETURN_RET(taihe->CheckRepeatOperation(option) == MSERR_OK, RetInfo(MSERR_EXT_API9_OK, "")); @@ -1553,6 +1554,363 @@ int32_t AVRecorderImpl::GetMaxAmplitude(int32_t &maxAmplitude) return MSERR_OK; } +void AVRecorderImpl::SetWatermarkSync(::ohos::multimedia::image::image::weak::PixelMap watermark, + ::ohos::multimedia::media::WatermarkConfig const& config) +{ + MediaTrace trace("AVRecorder::SetWatermarkSync"); + const std::string &opt = AVRecordergOpt::SET_WATERMARK; + MEDIA_LOGI("Taihe %{public}s Start", opt.c_str()); + + auto asyncCtx = std::make_unique(); + CHECK_AND_RETURN_LOG(asyncCtx != nullptr, "failed to get AsyncContext"); + asyncCtx->taihe = this; + CHECK_AND_RETURN_LOG(asyncCtx->taihe != nullptr, "failed to GetInstanceAndArgs"); + CHECK_AND_RETURN_LOG(asyncCtx->taihe->taskQue_ != nullptr, "taskQue is nullptr!"); + + if (asyncCtx->taihe->CheckStateMachine(opt) == MSERR_OK) { + if (asyncCtx->taihe->GetWatermarkParameter(asyncCtx, watermark, config) == MSERR_OK) { + asyncCtx->task_ = SetWatermarkTask(asyncCtx); + (void)asyncCtx->taihe->taskQue_->EnqueueTask(asyncCtx->task_); + } + } else { + SetRetInfoError(MSERR_INVALID_OPERATION, opt, ""); + } + if (asyncCtx->task_) { + auto result = asyncCtx->task_->GetResult(); + if (result.Value().first != MSERR_EXT_API9_OK) { + set_business_error(result.Value().first, result.Value().second); + } + } + asyncCtx.release(); + + MEDIA_LOGI("Taihe %{public}s End", opt.c_str()); +} + +int32_t AVRecorderImpl::GetWatermarkParameter(std::unique_ptr &asyncCtx, + ::ohos::multimedia::image::image::weak::PixelMap watermark, + ::ohos::multimedia::media::WatermarkConfig const& config) +{ + int32_t ret = GetWatermark(asyncCtx, watermark); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "failed to GetWatermark"); + ret = GetWatermarkConfig(asyncCtx, config); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "failed to GetWatermarkConfig"); + return MSERR_OK; +} + +int32_t AVRecorderImpl::GetWatermark(std::unique_ptr &asyncCtx, + ::ohos::multimedia::image::image::weak::PixelMap watermark) +{ + asyncCtx->pixelMap_ = Image::PixelMapImpl::GetPixelMap(watermark); + CHECK_AND_RETURN_RET(asyncCtx->pixelMap_ != nullptr, + (SetRetInfoError(MSERR_INVALID_VAL, "GetPixelMap", "PixelMap"), MSERR_INVALID_VAL)); + return MSERR_OK; +} + +int32_t AVRecorderImpl::GetWatermarkConfig(std::unique_ptr &asyncCtx, + ::ohos::multimedia::media::WatermarkConfig const& config) +{ + asyncCtx->watermarkConfig_ = std::make_shared(); + asyncCtx->watermarkConfig_->top = config.top; + CHECK_AND_RETURN_RET(asyncCtx->watermarkConfig_->top >= 0, + (SetRetInfoError(MSERR_PARAMETER_VERIFICATION_FAILED, "GetWatermarkConfig", "top", + "config top cannot be null or less than zero"), MSERR_PARAMETER_VERIFICATION_FAILED)); + + asyncCtx->watermarkConfig_->left = config.left; + CHECK_AND_RETURN_RET(asyncCtx->watermarkConfig_->left >= 0, + (SetRetInfoError(MSERR_PARAMETER_VERIFICATION_FAILED, "GetWatermarkConfig", "left", + "config left cannot be null or less than zero"), MSERR_PARAMETER_VERIFICATION_FAILED)); + return MSERR_OK; +} + +std::shared_ptr> AVRecorderImpl::SetWatermarkTask( + const std::unique_ptr &asyncCtx) +{ + return std::make_shared>([taihe = asyncCtx->taihe, &pixelMap = asyncCtx->pixelMap_, + &watermarkConfig = asyncCtx->watermarkConfig_]() { + const std::string &option = AVRecordergOpt::SET_WATERMARK; + MEDIA_LOGI("%{public}s Start", option.c_str()); + + CHECK_AND_RETURN_RET(taihe != nullptr, + GetRetInfo(MSERR_INVALID_OPERATION, option, "")); + + CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, + GetRetInfo(MSERR_INVALID_OPERATION, option, "")); + + CHECK_AND_RETURN_RET(taihe->CheckRepeatOperation(option) == MSERR_OK, + RetInfo(MSERR_EXT_API9_OK, "")); + bool isWatermarkSupported = false; + int32_t ret = taihe->IsWatermarkSupported(isWatermarkSupported); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, GetRetInfo(MSERR_UNKNOWN, "SetWatermarkTask", ""), + "IsWatermarkSupported fail"); + CHECK_AND_RETURN_RET_LOG(isWatermarkSupported, GetRetInfo(MSERR_UNSUPPORT_WATER_MARK, "SetWatermarkTask", ""), + "capability not supported"); + + ret = taihe->SetWatermark(pixelMap, watermarkConfig); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, GetRetInfo(ret, "SetWatermarkTask", ""), + "SetWatermarkTask failed"); + + MEDIA_LOGI("%{public}s End", option.c_str()); + return RetInfo(MSERR_EXT_API9_OK, ""); + }); +} + +int32_t AVRecorderImpl::SetWatermark(std::shared_ptr &pixelMap, + std::shared_ptr &watermarkConfig) +{ +#ifndef CROSS_PLATFORM + MEDIA_LOGD("pixelMap Width %{public}d, height %{public}d, pixelformat %{public}d, RowStride %{public}d", + pixelMap->GetWidth(), pixelMap->GetHeight(), pixelMap->GetPixelFormat(), pixelMap->GetRowStride()); + CHECK_AND_RETURN_RET_LOG(pixelMap->GetPixelFormat() == OHOS::Media::PixelFormat::RGBA_8888, MSERR_INVALID_VAL, + "Invalid pixel format"); + std::shared_ptr avBufferConfig = std::make_shared(); + int32_t ret = ConfigAVBufferMeta(pixelMap, watermarkConfig, avBufferConfig); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_INVALID_VAL, "ConfigAVBufferMeta is failed"); + Image::sptr surfaceBuffer = Image::SurfaceBuffer::Create(); + Image::BufferRequestConfig bufferConfig = { + .width = pixelMap->GetWidth(), + .height = pixelMap->GetHeight(), + .strideAlignment = 0x8, + .format = Image::GraphicPixelFormat::GRAPHIC_PIXEL_FMT_RGBA_8888, + .usage = Image::BUFFER_USAGE_CPU_READ | Image::BUFFER_USAGE_CPU_WRITE | Image::BUFFER_USAGE_MEM_DMA, + .timeout = 0, + }; + surfaceBuffer->Alloc(bufferConfig); + + MEDIA_LOGD("surface size %{public}d, surface stride %{public}d", + surfaceBuffer->GetSize(), surfaceBuffer->GetStride()); + + for (int i = 0; i < pixelMap->GetHeight(); i++) { + ret = memcpy_s(static_cast(surfaceBuffer->GetVirAddr()) + i * surfaceBuffer->GetStride(), + pixelMap->GetRowStride(), pixelMap->GetPixels() + i * pixelMap->GetRowStride(), pixelMap->GetRowStride()); + CHECK_AND_RETURN_RET_LOG(ret == 0, MSERR_INVALID_VAL, "memcpy failed"); + } + std::shared_ptr waterMarkBuffer = AVBuffer::CreateAVBuffer(surfaceBuffer); + CHECK_AND_RETURN_RET_LOG(waterMarkBuffer != nullptr, MSERR_NO_MEMORY, "surfaceBuffer is nullptr"); + waterMarkBuffer->meta_ = avBufferConfig; + return recorder_->SetWatermark(waterMarkBuffer); +#endif + return MSERR_OK; +} + +int32_t AVRecorderImpl::ConfigAVBufferMeta(std::shared_ptr &pixelMap, + std::shared_ptr &watermarkConfig, std::shared_ptr &meta) +{ + int32_t top = watermarkConfig->top; + int32_t left = watermarkConfig->left; + int32_t watermarkWidth = pixelMap->GetWidth(); + int32_t watermarkHeight = pixelMap->GetHeight(); + meta->Set(true); + switch (rotation_) { + case OHOS::Media::VIDEO_ROTATION_0: + meta->Set(left); + meta->Set(top); + meta->Set(watermarkWidth); + meta->Set(watermarkHeight); + break; + case OHOS::Media::VIDEO_ROTATION_90: + MEDIA_LOGI("rotation %{public}d", OHOS::Media::VIDEO_ROTATION_90); + CHECK_AND_RETURN_RET_LOG(videoFrameHeight_ - left - watermarkWidth >= 0, + MSERR_INVALID_VAL, "invalid watermark"); + pixelMap->rotate(OHOS::Media::VIDEO_ROTATION_270); + meta->Set(top); + meta->Set(videoFrameHeight_ - left - watermarkWidth); + meta->Set(watermarkHeight); + meta->Set(watermarkWidth); + break; + case OHOS::Media::VIDEO_ROTATION_180: + MEDIA_LOGI("rotation %{public}d", OHOS::Media::VIDEO_ROTATION_180); + CHECK_AND_RETURN_RET_LOG(videoFrameWidth_-left-watermarkWidth >= 0, + MSERR_INVALID_VAL, "invalid watermark"); + CHECK_AND_RETURN_RET_LOG(videoFrameHeight_-top-watermarkHeight >= 0, + MSERR_INVALID_VAL, "invalid watermark"); + pixelMap->rotate(OHOS::Media::VIDEO_ROTATION_180); + meta->Set(videoFrameWidth_-left-watermarkWidth); + meta->Set(videoFrameHeight_-top-watermarkHeight); + meta->Set(watermarkWidth); + meta->Set(watermarkHeight); + break; + case OHOS::Media::VIDEO_ROTATION_270: + MEDIA_LOGI("rotation %{public}d", OHOS::Media::VIDEO_ROTATION_270); + CHECK_AND_RETURN_RET_LOG(videoFrameHeight_ - left - watermarkWidth >= 0, + MSERR_INVALID_VAL, "invalid watermark"); + pixelMap->rotate(OHOS::Media::VIDEO_ROTATION_90); + meta->Set(videoFrameWidth_ - top - watermarkHeight); + meta->Set(left); + meta->Set(watermarkHeight); + meta->Set(watermarkWidth); + break; + default: + break; + } + return MSERR_OK; +} + +optional<::ohos::multimedia::audio::AudioCapturerChangeInfo> AVRecorderImpl::GetCurrentAudioCapturerInfoSync() +{ + MediaTrace trace("AVRecorder::GetCurrentAudioCapturerInfoSync"); + const std::string &opt = AVRecordergOpt::GET_CURRENT_AUDIO_CAPTURER_INFO; + MEDIA_LOGI("Taihe %{public}s Start", opt.c_str()); + auto res = optional<::ohos::multimedia::audio::AudioCapturerChangeInfo>(std::nullopt); + auto asyncCtx = std::make_unique(); + CHECK_AND_RETURN_RET_LOG(asyncCtx != nullptr, res, "failed to get AsyncContext"); + asyncCtx->taihe = this; + CHECK_AND_RETURN_RET_LOG(asyncCtx->taihe != nullptr, res, "failed to GetJsInstanceAndArgs"); + CHECK_AND_RETURN_RET_LOG(asyncCtx->taihe->taskQue_ != nullptr, res, "taskQue is nullptr!"); + ::ohos::multimedia::audio::AudioCapturerChangeInfo changeInfo = GetAudioDefaultInfo(); + + if (asyncCtx->taihe->CheckStateMachine(opt) == MSERR_OK) { + asyncCtx->task_ = GetCurrentCapturerChangeInfoTask(asyncCtx); + (void)asyncCtx->taihe->taskQue_->EnqueueTask(asyncCtx->task_); + asyncCtx->opt_ = opt; + } else { + SetRetInfoError(MSERR_INVALID_OPERATION, opt, ""); + } + if (asyncCtx->task_) { + auto result = asyncCtx->task_->GetResult(); + if (result.Value().first != MSERR_EXT_API9_OK) { + set_business_error(result.Value().first, result.Value().second); + } + if ((result.Value().first == MSERR_EXT_API9_OK) && + (asyncCtx->opt_ == AVRecordergOpt::GET_CURRENT_AUDIO_CAPTURER_INFO)) { + GetAudioCapturerChangeInfo(asyncCtx, changeInfo); + } + } + asyncCtx.release(); + + MEDIA_LOGI("Taihe %{public}s End", opt.c_str()); + return optional<::ohos::multimedia::audio::AudioCapturerChangeInfo>(std::in_place, changeInfo); +} + +void AVRecorderImpl::GetAudioCapturerChangeInfo( + const std::unique_ptr &asyncCtx, ::ohos::multimedia::audio::AudioCapturerChangeInfo &res) +{ + ohos::multimedia::audio::AudioState::key_t audioStateKey; + MediaTaiheUtils::GetEnumKeyByValue( + asyncCtx->changeInfo_.capturerState, audioStateKey); + ohos::multimedia::audio::SourceType::key_t sourceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + asyncCtx->changeInfo_.capturerInfo.sourceType, sourceTypeKey); + + ::ohos::multimedia::audio::AudioCapturerInfo audioCapturerInfo { + std::move(::ohos::multimedia::audio::SourceType(sourceTypeKey)), + asyncCtx->changeInfo_.capturerInfo.capturerFlags + }; + + std::vector<::ohos::multimedia::audio::AudioDeviceDescriptor> audioDeviceDescriptor; + audioDeviceDescriptor.push_back(GetDeviceInfo(asyncCtx)); + res.streamId = asyncCtx->changeInfo_.sessionId; + res.clientUid = asyncCtx->changeInfo_.clientUID; + res.capturerState = ::ohos::multimedia::audio::AudioState(audioStateKey); + res.muted = optional(std::in_place_t{}, asyncCtx->changeInfo_.muted); + res.deviceDescriptors = array<::ohos::multimedia::audio::AudioDeviceDescriptor>(audioDeviceDescriptor); + res.capturerInfo = audioCapturerInfo; +} + +::ohos::multimedia::audio::AudioDeviceDescriptor AVRecorderImpl::GetDeviceInfo( + const std::unique_ptr &asyncCtx) +{ + ohos::multimedia::audio::DeviceRole::key_t deviceRoleKey; + MediaTaiheUtils::GetEnumKeyByValue( + asyncCtx->changeInfo_.inputDeviceInfo.deviceRole, deviceRoleKey); + ohos::multimedia::audio::DeviceType::key_t deviceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + asyncCtx->changeInfo_.inputDeviceInfo.deviceType, deviceTypeKey); + taihe::string name = MediaTaiheUtils::ToTaiheString(asyncCtx->changeInfo_.inputDeviceInfo.deviceName); + taihe::string address = + MediaTaiheUtils::ToTaiheString(asyncCtx->changeInfo_.inputDeviceInfo.macAddress); + std::vector samplingRateVec( + asyncCtx->changeInfo_.inputDeviceInfo.audioStreamInfo.samplingRate.begin(), + asyncCtx->changeInfo_.inputDeviceInfo.audioStreamInfo.samplingRate.end()); + std::vector channelsVec(asyncCtx->changeInfo_.inputDeviceInfo.audioStreamInfo.channels.begin(), + asyncCtx->changeInfo_.inputDeviceInfo.audioStreamInfo.channels.end()); + taihe::string networkId = + MediaTaiheUtils::ToTaiheString(asyncCtx->changeInfo_.inputDeviceInfo.networkId); + taihe::string displayName = MediaTaiheUtils::ToTaiheString( + asyncCtx->changeInfo_.inputDeviceInfo.displayName); + ohos::multimedia::audio::AudioEncodingType::key_t audioEncodingTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + asyncCtx->changeInfo_.inputDeviceInfo.audioStreamInfo.encoding, audioEncodingTypeKey); + std::vector channelMasks; + channelMasks.push_back(asyncCtx->changeInfo_.inputDeviceInfo.channelMasks); + std::vector<::ohos::multimedia::audio::AudioEncodingType> AudioEncodingType; + AudioEncodingType.push_back(audioEncodingTypeKey); + + ::ohos::multimedia::audio::AudioDeviceDescriptor descriptor { + std::move(::ohos::multimedia::audio::DeviceRole(deviceRoleKey)), + std::move(::ohos::multimedia::audio::DeviceType(deviceTypeKey)), + std::move(asyncCtx->changeInfo_.inputDeviceInfo.deviceId), + std::move(name), + std::move(address), + array(samplingRateVec), + array(channelsVec), + array(channelMasks), + std::move(networkId), + std::move(asyncCtx->changeInfo_.inputDeviceInfo.interruptGroupId), + std::move(asyncCtx->changeInfo_.inputDeviceInfo.volumeGroupId), + std::move(displayName), + optional<::taihe::array<::ohos::multimedia::audio::AudioEncodingType>>( + std::in_place_t{}, array<::ohos::multimedia::audio::AudioEncodingType>(AudioEncodingType)), + optional(std::nullopt), + optional(std::nullopt), + }; + return descriptor; +} + +::ohos::multimedia::audio::AudioCapturerChangeInfo AVRecorderImpl::GetAudioDefaultInfo() +{ + int32_t res = -1; + ohos::multimedia::audio::AudioState::key_t audioStateKey; + MediaTaiheUtils::GetEnumKeyByValue( + res, audioStateKey); + ohos::multimedia::audio::SourceType::key_t sourceTypeKey; + MediaTaiheUtils::GetEnumKeyByValue( + res, sourceTypeKey); + ::ohos::multimedia::audio::AudioCapturerInfo audioCapturerInfo { + std::move(::ohos::multimedia::audio::SourceType(sourceTypeKey)), + res, + }; + std::vector<::ohos::multimedia::audio::AudioDeviceDescriptor> audioDeviceDescriptor; + ::ohos::multimedia::audio::AudioCapturerChangeInfo audioCapturerChangeInfo { + std::move(res), std::move(res), + std::move(audioCapturerInfo), + std::move(::ohos::multimedia::audio::AudioState(audioStateKey)), + array<::ohos::multimedia::audio::AudioDeviceDescriptor>(audioDeviceDescriptor), + optional(std::nullopt), + }; + return audioCapturerChangeInfo; +} + +std::shared_ptr> AVRecorderImpl::GetCurrentCapturerChangeInfoTask( + const std::unique_ptr &asyncCtx) +{ + return std::make_shared>([taihe = asyncCtx->taihe, &changeInfo = asyncCtx->changeInfo_]() { + const std::string &option = AVRecordergOpt::GET_CURRENT_AUDIO_CAPTURER_INFO; + MEDIA_LOGI("%{public}s Start", option.c_str()); + + CHECK_AND_RETURN_RET(taihe != nullptr, + GetRetInfo(MSERR_INVALID_OPERATION, option, "")); + + CHECK_AND_RETURN_RET(taihe->CheckStateMachine(option) == MSERR_OK, + GetRetInfo(MSERR_INVALID_OPERATION, option, "")); + + CHECK_AND_RETURN_RET(taihe->CheckRepeatOperation(option) == MSERR_OK, + RetInfo(MSERR_EXT_API9_OK, "")); + + int32_t ret = taihe->GetCurrentCapturerChangeInfo(changeInfo); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, GetRetInfo(MSERR_INVALID_VAL, "GetCurrentCapturerChangeInfoTask", ""), + "get GetCurrentCapturerChangeInfoTask failed"); + + MEDIA_LOGI("%{public}s End", option.c_str()); + return RetInfo(MSERR_EXT_API9_OK, ""); + }); +} + +int32_t AVRecorderImpl::GetCurrentCapturerChangeInfo(AudioRecorderChangeInfo &changeInfo) +{ + int32_t ret = recorder_->GetCurrentCapturerChangeInfo(changeInfo); + return ret; +} + RetInfo AVRecorderImpl::GetInputSurface() { CHECK_AND_RETURN_RET_LOG(withVideo_, GetRetInfo(MSERR_INVALID_OPERATION, "GetInputSurface", "", @@ -1722,10 +2080,35 @@ void AVRecorderImpl::OffStateChange(optional_view callback) +{ + MediaTrace trace("AVRecorderTaihe::OnAudioCapturerChange"); + MEDIA_LOGD("TaiheOnAudioCapturerChange In"); + + ani_env *env = taihe::get_env(); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); + std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); + std::shared_ptr autoRef = std::make_shared(env, cacheCallback); + SetCallbackReference(AVRecorderEvent::EVENT_AUDIO_CAPTURE_CHANGE, autoRef); + MEDIA_LOGI("0x%{public}06" PRIXPTR " TaiheOnStateChange callbackName: stateChange success", FAKE_POINTER(this)); + return; +} + +void AVRecorderImpl::OffAudioCapturerChange( + ::taihe::optional_view<::taihe::callback> callback) +{ + MediaTrace trace("AVRecorderTaihe::OffAudioCapturerChange"); + MEDIA_LOGD("TaiheOffAudioCapturerChange In"); + + CancelCallbackReference(AVRecorderEvent::EVENT_AUDIO_CAPTURE_CHANGE); +} + void AVRecorderImpl::OnPhotoAssetAvailable(callback_view callback) { MediaTrace trace("AVRecorderTaihe::OnPhotoAssetAvailable"); @@ -1745,7 +2128,7 @@ void AVRecorderImpl::OffPhotoAssetAvailable(optional_view CreateAVScreenCaptureRecorderSync() return optional(std::in_place, res); } -void ReportAVScreenCaptureUserChoiceSync(double sessionId, string_view choice) +void ReportAVScreenCaptureUserChoiceSync(int32_t sessionId, string_view choice) { MediaTrace trace("AVScreenCapture::TaiheReportAVScreenCaptureUserChoice"); const std::string &opt = AVScreenCapturegOpt::REPORT_USER_CHOICE; MEDIA_LOGI("Taihe %{public}s Start", opt.c_str()); - MEDIA_LOGI("TaiheReportAVScreenCaptureUserChoice sessionId: %{public}f, choice: %{public}s", + MEDIA_LOGI("TaiheReportAVScreenCaptureUserChoice sessionId: %{public}d, choice: %{public}s", sessionId, static_cast(choice).c_str()); auto asyncCtx = std::make_unique(); CHECK_AND_RETURN_LOG(asyncCtx != nullptr, "failed to get AsyncContext"); @@ -450,7 +450,7 @@ std::shared_ptr> AVScreenCaptureRecorderImpl::GetSkipPrivac }); } -void AVScreenCaptureRecorderImpl::SkipPrivacyModeSync(::taihe::array_view windowIDs) +void AVScreenCaptureRecorderImpl::SkipPrivacyModeSync(::taihe::array_view windowIDs) { MediaTrace trace("AVScreenCapture::TaiheSkipPrivacyMode"); const std::string &option = AVScreenCapturegOpt::SKIP_PRIVACY_MODE; diff --git a/frameworks/taihe/media/src/avtranscoder_callback_taihe.cpp b/frameworks/taihe/media/src/avtranscoder_callback_taihe.cpp index aeb1e0253..14d7bd060 100644 --- a/frameworks/taihe/media/src/avtranscoder_callback_taihe.cpp +++ b/frameworks/taihe/media/src/avtranscoder_callback_taihe.cpp @@ -165,9 +165,9 @@ void AVTransCoderCallback::OnTaiheProgressUpdateCallback(AVTransCoderTaiheCallba auto func = ref->callbackRef_; CHECK_AND_BREAK_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); - (*cacheCallback)(static_cast(taiheCb->progress)); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + (*cacheCallback)(static_cast(taiheCb->progress)); } while (0); delete taiheCb; } diff --git a/frameworks/taihe/media/src/avtranscoder_taihe.cpp b/frameworks/taihe/media/src/avtranscoder_taihe.cpp index 89cc25eeb..14a0b74f6 100644 --- a/frameworks/taihe/media/src/avtranscoder_taihe.cpp +++ b/frameworks/taihe/media/src/avtranscoder_taihe.cpp @@ -179,14 +179,14 @@ RetInfo AVTranscoderImpl::SetOutputFile(int32_t fd) return RetInfo(MSERR_EXT_API9_OK, ""); } -double AVTranscoderImpl::GetFdDst() +int32_t AVTranscoderImpl::GetFdDst() { MediaTrace trace("AVTranscoderImpl::get url"); MEDIA_LOGD("TaiheGetUrl Out Current Url: %{public}s", srcUrl_.c_str()); return dstFd_; } -void AVTranscoderImpl::SetFdDst(double fdDst) +void AVTranscoderImpl::SetFdDst(int32_t fdDst) { MediaTrace trace("AVTranscoderImpl::set fd"); auto asyncCtx = std::make_unique(); @@ -215,8 +215,8 @@ ohos::multimedia::media::AVFileDescriptor AVTranscoderImpl::GetFdSrc() MediaTrace trace("AVTranscoderImpl::get url"); ohos::multimedia::media::AVFileDescriptor fdSrc; fdSrc.fd = srcFd_.fd; - fdSrc.offset = optional(std::in_place_t{}, srcFd_.offset); - fdSrc.length = optional(std::in_place_t{}, srcFd_.length); + fdSrc.offset = optional(std::in_place_t{}, srcFd_.offset); + fdSrc.length = optional(std::in_place_t{}, srcFd_.length); MEDIA_LOGD("TaiheGetUrl Out Current Url: %{public}s", srcUrl_.c_str()); return fdSrc; } @@ -510,15 +510,15 @@ void AVTranscoderImpl::OffComplete(optional_view> call MEDIA_LOGI("OffComplete End"); } -void AVTranscoderImpl::OnProgressUpdate(callback_view callback) +void AVTranscoderImpl::OnProgressUpdate(callback_view callback) { MediaTrace trace("AVTranscoderImpl::OnProgressUpdate"); MEDIA_LOGI("OnProgressUpdate Start"); std::string callbackName = STATE_PROGRESSUPDATE; ani_env *env = get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); @@ -526,7 +526,7 @@ void AVTranscoderImpl::OnProgressUpdate(callback_view callback) MEDIA_LOGI("OnProgressUpdate End"); } -void AVTranscoderImpl::OffProgressUpdate(optional_view> callback) +void AVTranscoderImpl::OffProgressUpdate(optional_view> callback) { MediaTrace trace("AVTranscoderImpl::OffProgressUpdate"); MEDIA_LOGI("OffProgressUpdate Start"); diff --git a/frameworks/taihe/media/src/helper_data_source_callback_taihe.cpp b/frameworks/taihe/media/src/helper_data_source_callback_taihe.cpp index dc1fb5395..c5ba5a090 100644 --- a/frameworks/taihe/media/src/helper_data_source_callback_taihe.cpp +++ b/frameworks/taihe/media/src/helper_data_source_callback_taihe.cpp @@ -117,12 +117,11 @@ void HelperDataSourceCallback::UvWork(HelperDataSourceTHCallbackWraper *cbWrap, auto func = ref->callbackRef_; CHECK_AND_BREAK_LOG(func != nullptr, "failed to get callback"); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(func); - taihe::optional_view posOption = taihe::optional_view(std::nullopt); + taihe::optional_view posOption = taihe::optional_view(std::nullopt); if (event->pos_ != -1) { - double pos = static_cast(event->pos_); - posOption = taihe::optional_view(&pos); + posOption = taihe::optional_view(&event->pos_); } - event->readSize_ = (*cacheCallback)(dataVector, static_cast(event->length_), posOption); + event->readSize_ = (*cacheCallback)(dataVector, static_cast(event->length_), posOption); std::unique_lock lock(event->mutexCond_); event->setResult_ = true; event->cond_.notify_all(); diff --git a/frameworks/taihe/media/src/media_source_loader_callback_taihe.cpp b/frameworks/taihe/media/src/media_source_loader_callback_taihe.cpp index 8bf0c7919..a03ee890b 100644 --- a/frameworks/taihe/media/src/media_source_loader_callback_taihe.cpp +++ b/frameworks/taihe/media/src/media_source_loader_callback_taihe.cpp @@ -87,12 +87,11 @@ int64_t MediaSourceLoaderCallback::Open(std::shared_ptr &request CHECK_AND_BREAK_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", taiheCb_->callbackName_.c_str()); auto func = ref->callbackRef_; CHECK_AND_BREAK_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast> + (func); taiheCb_->uuid_ = (*cacheCallback)(static_cast< - ::ohos::multimedia::media::weak::MediaSourceLoadingRequest>( + ohos::multimedia::media::weak::MediaSourceLoadingRequest>( MediaSourceLoadingRequestImpl::CreateLoadingRequest(taiheCb_->request_))); std::unique_lock lock(taiheCb_->mutexCond_); taiheCb_->setResult_ = true; @@ -130,10 +129,9 @@ void MediaSourceLoaderCallback::Read(int64_t uuid, int64_t requestedOffset, int6 CHECK_AND_RETURN_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", taiheCb_->callbackName_.c_str()); auto func = ref->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); - (*cacheCallback)(static_cast(taiheCb_->uuid_), static_cast(taiheCb_->requestedOffset_), - static_cast(taiheCb_->requestedLength_)); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + (*cacheCallback)(taiheCb_->uuid_, taiheCb_->requestedOffset_, taiheCb_->requestedLength_); } while (0); } @@ -161,9 +159,9 @@ void MediaSourceLoaderCallback::Close(int64_t uuid) CHECK_AND_RETURN_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", taiheCb_->callbackName_.c_str()); auto func = ref->callbackRef_; CHECK_AND_RETURN_LOG(func != nullptr, "failed to get callback"); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); - (*cacheCallback)(static_cast(taiheCb_->uuid_)); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); + (*cacheCallback)(taiheCb_->uuid_); } while (0); } diff --git a/frameworks/taihe/media/src/media_source_loading_request_taihe.cpp b/frameworks/taihe/media/src/media_source_loading_request_taihe.cpp index d65e77c47..3092b4ada 100644 --- a/frameworks/taihe/media/src/media_source_loading_request_taihe.cpp +++ b/frameworks/taihe/media/src/media_source_loading_request_taihe.cpp @@ -58,7 +58,7 @@ optional> MediaSourceLoadingRequestImpl::GetHeader() return optional>(std::in_place_t{}, taiheHeader); } -optional MediaSourceLoadingRequestImpl::RespondData(double uuid, double offset, array_view buffer) +optional MediaSourceLoadingRequestImpl::RespondData(double uuid, double offset, array_view buffer) { MediaTrace trace("MediaSourceLoadingRequestTaihe::respondData"); MEDIA_LOGI("respondData In"); @@ -67,12 +67,12 @@ optional MediaSourceLoadingRequestImpl::RespondData(double uuid, double auto bufferInner = std::make_shared(static_cast(arrayBufferSize), AVSharedMemory::FLAGS_READ_WRITE, "userBuffer"); - CHECK_AND_RETURN_RET_LOG(bufferInner != nullptr, optional(std::nullopt), "get buffer fail"); + CHECK_AND_RETURN_RET_LOG(bufferInner != nullptr, optional(std::nullopt), "get buffer fail"); bufferInner->Init(); bufferInner->Write(static_cast(arrayBuffer), arrayBufferSize); MEDIA_LOGI("respondData getSize: %{public}d", bufferInner->GetSize()); - double res = request_->RespondData(uuid, offset, bufferInner); - return optional(std::in_place_t{}, res); + int32_t res = request_->RespondData(uuid, offset, bufferInner); + return optional(std::in_place_t{}, res); } void MediaSourceLoadingRequestImpl::RespondHeader(double uuid, optional_view> header, diff --git a/frameworks/taihe/media/src/media_source_taihe.cpp b/frameworks/taihe/media/src/media_source_taihe.cpp index 9f88863b1..e3b92aec5 100644 --- a/frameworks/taihe/media/src/media_source_taihe.cpp +++ b/frameworks/taihe/media/src/media_source_taihe.cpp @@ -160,22 +160,22 @@ void MediaSourceImpl::SetMediaResourceLoaderDelegate(::ohos::multimedia::media:: mediaSourceLoaderCb_ = std::make_shared(); CHECK_AND_RETURN_LOG(mediaSourceLoaderCb_ != nullptr, "Cb_ is nullptr"); ani_env *env = get_env(); - std::shared_ptr> + std::shared_ptr> taiheCallbackOpen = std::make_shared>(resourceLoader.open); + int64_t(ohos::multimedia::media::weak::MediaSourceLoadingRequest)>>(resourceLoader.open); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallbackOpen); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); mediaSourceLoaderCb_->SaveCallbackReference(FunctionName::SOURCE_OPEN, autoRef); - std::shared_ptr> taiheCallbackRead = - std::make_shared>(resourceLoader.read); + std::shared_ptr> taiheCallbackRead = + std::make_shared>(resourceLoader.read); cacheCallback = std::reinterpret_pointer_cast(taiheCallbackRead); autoRef = std::make_shared(env, cacheCallback); mediaSourceLoaderCb_->SaveCallbackReference(FunctionName::SOURCE_READ, autoRef); - std::shared_ptr> taiheCallbackClose = - std::make_shared>(resourceLoader.close); + std::shared_ptr> taiheCallbackClose = + std::make_shared>(resourceLoader.close); cacheCallback = std::reinterpret_pointer_cast(taiheCallbackClose); autoRef = std::make_shared(env, cacheCallback); mediaSourceLoaderCb_->SaveCallbackReference(FunctionName::SOURCE_CLOSE, autoRef); diff --git a/frameworks/taihe/media/src/media_taihe_utils.cpp b/frameworks/taihe/media/src/media_taihe_utils.cpp index a770792f4..1b1a71c5a 100644 --- a/frameworks/taihe/media/src/media_taihe_utils.cpp +++ b/frameworks/taihe/media/src/media_taihe_utils.cpp @@ -88,6 +88,27 @@ bool MediaTaiheUtils::GetEnumKeyByStringValue(int32_t value, + typename ohos::multimedia::audio::AudioEncodingType::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::DeviceType::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::DeviceRole::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::SourceType::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::AudioState::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::StreamUsage::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::AudioVolumeMode::key_t &key); +template bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, typename ohos::multimedia::media::HdrType::key_t &key); template @@ -108,6 +129,25 @@ template bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, typename StateChangeReason::key_t &key); template bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, typename BufferingInfoType::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::AudioEffectMode::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::InterruptType::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::InterruptForceType::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::InterruptHint::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::AudioStreamDeviceChangeReason::key_t &key); +template +bool MediaTaiheUtils::GetEnumKeyByValue(int32_t value, + typename ohos::multimedia::audio::InterruptMode::key_t &key); + ani_object MediaTaiheUtils::ToBusinessError(ani_env *env, int32_t code, const std::string &message) { @@ -149,53 +189,6 @@ ani_object MediaTaiheUtils::CreatePixelMap(ani_env *env, OHOS::Media::PixelMap & return aniObject; } -ani_object MediaTaiheUtils::CreateMediaKeySystemInfo(ani_env *env, ANI::Media::MediaKeySystemInfo &mediaKeySystemInfo) -{ - ani_class cls {}; - static const char *className = "@ohos.multimedia.drm.drm.MediaKeySystemInfo"; - CHECK_AND_RETURN_RET_LOG(env->FindClass(className, &cls) == ANI_OK, nullptr, - "Failed to find class: %{public}s", className); - ani_method ctorMethod {}; - CHECK_AND_RETURN_RET_LOG(env->Class_FindMethod(cls, "", nullptr, &ctorMethod) == ANI_OK, nullptr, - "Failed to find method: "); - ani_object aniObject {}; - CHECK_AND_RETURN_RET_LOG(env->Object_New(cls, ctorMethod, &aniObject) == ANI_OK, nullptr, - "Call method failed."); - - ani_method uuidSetter {}; - CHECK_AND_RETURN_RET_LOG(env->Class_FindMethod(cls, "uuid", nullptr, &uuidSetter) == ANI_OK, nullptr, - "Failed to find method: uuid"); - CHECK_AND_RETURN_RET_LOG(env->Object_CallMethod_Void(aniObject, uuidSetter, - ToAniString(env, mediaKeySystemInfo.uuid)) == ANI_OK, nullptr, "uuid fail"); - - ani_class clsAry {}; - static const std::string classNameAry = "escompat.Array"; - if (env->FindClass(classNameAry.c_str(), &clsAry)) { - printf("Can't find escompat.Array."); - } - - ani_method arrayConstructor {}; - if (env->Class_FindMethod(clsAry, "", "i:", &arrayConstructor)) { - printf("Can't find method in escompat.Array."); - } - - if (env->Object_New(clsAry, arrayConstructor, &aniObject, mediaKeySystemInfo.pssh.size())) { - printf("Call method failed."); - } - - ani_method setMethod {}; - if (env->Class_FindMethod(clsAry, "$_set", "iC{std.core.Object}:", &setMethod)) { - printf("Can't find method $_set in escompat.Array."); - } - for (size_t i = 0; i < mediaKeySystemInfo.pssh.size(); i++) { - ani_int aniInt = static_cast(mediaKeySystemInfo.pssh[i]); - if (env->Object_CallMethod_Void(aniObject, setMethod, (ani_int)i, aniInt)) { - printf("Call method $_set failed."); - } - } - return aniObject; -} - ani_string MediaTaiheUtils::ToAniString(ani_env *env, const std::string &str) { ani_string aniString; diff --git a/frameworks/taihe/soundpool/include/sound_pool_taihe.h b/frameworks/taihe/soundpool/include/sound_pool_taihe.h index e19fcd0e5..e0215cef2 100644 --- a/frameworks/taihe/soundpool/include/sound_pool_taihe.h +++ b/frameworks/taihe/soundpool/include/sound_pool_taihe.h @@ -35,24 +35,25 @@ class SoundPoolImpl { public: SoundPoolImpl(int32_t maxStreams, uintptr_t audioRendererInfo); - double LoadSync(string_view uri); - double LoadWithFdSync(double fd, double offset, double length); - double PlaySync(double soundID, optional_view params); - double PlayWithoutParam(double soundID); - double PlayWithParam(double soundID, PlayParameters const& params); - void StopSync(double streamID); - void UnloadSync(double soundID); + int32_t LoadSync(string_view uri); + int32_t LoadWithFdSync(int32_t fd, double offset, double length); + int32_t PlaySync(int32_t soundID, optional_view params); + int32_t PlayWithoutParam(int32_t soundID); + int32_t PlayWithParam(int32_t soundID, PlayParameters const& params); + void StopSync(int32_t streamID); + void UnloadSync(int32_t soundID); void ReleaseSync(); - void SetLoopSync(double streamID, double loop); - void SetPrioritySync(double streamID, double priority); - void SetVolumeSync(double streamID, double leftVolume, double rightVolume); + void SetLoopSync(int32_t streamID, int32_t loop); + void SetPrioritySync(int32_t streamID, int32_t priority); + void SetRateSync(int32_t streamID, ::ohos::multimedia::audio::AudioRendererRate rate); + void SetVolumeSync(int32_t streamID, double leftVolume, double rightVolume); void OnError(callback_view callback); void OffError(); - void OnPlayFinishedWithStreamId(callback_view callback); + void OnPlayFinishedWithStreamId(callback_view callback); void OffPlayFinishedWithStreamId(); - void OnLoadComplete(callback_view callback); + void OnLoadComplete(callback_view callback); void OffLoadComplete(); void OnPlayFinished(callback_view callback); @@ -88,6 +89,7 @@ private: int32_t priority_ = 0; float leftVolume_ = 0.0f; float rightVolume_ = 0.0f; + OHOS::AudioStandard::AudioRendererRate renderRate_ = OHOS::AudioStandard::AudioRendererRate::RENDER_RATE_NORMAL; }; struct SoundPoolAsyncContext { diff --git a/frameworks/taihe/soundpool/src/sound_pool_callback_taihe.cpp b/frameworks/taihe/soundpool/src/sound_pool_callback_taihe.cpp index 248d4fa92..c0a36c9c3 100644 --- a/frameworks/taihe/soundpool/src/sound_pool_callback_taihe.cpp +++ b/frameworks/taihe/soundpool/src/sound_pool_callback_taihe.cpp @@ -227,8 +227,8 @@ void SoundPoolCallBackTaihe::OnTaiheloadCompletedCallBack(SoundPoolTaiheCallBack CHECK_AND_BREAK_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", request.c_str()); auto func = ref->callbackRef_; CHECK_AND_BREAK_LOG(func != nullptr, "%{public}s failed to get callback", request.c_str()); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); (*cacheCallback)(taiheCb->loadSoundId); } while (0); delete taiheCb; @@ -244,8 +244,8 @@ void SoundPoolCallBackTaihe::OnTaiheplayCompletedCallBack(SoundPoolTaiheCallBack CHECK_AND_BREAK_LOG(ref != nullptr, "%{public}s AutoRef is nullptr", request.c_str()); auto func = ref->callbackRef_; CHECK_AND_BREAK_LOG(func != nullptr, "%{public}s failed to get callback", request.c_str()); - std::shared_ptr> cacheCallback = - std::reinterpret_pointer_cast>(func); + std::shared_ptr> cacheCallback = + std::reinterpret_pointer_cast>(func); (*cacheCallback)(taiheCb->playFinishedStreamID); } else if (request == SoundPoolEvent::EVENT_PLAY_FINISHED) { MEDIA_LOGD("OnTaiheloadCompletedCallBack is called"); diff --git a/frameworks/taihe/soundpool/src/sound_pool_taihe.cpp b/frameworks/taihe/soundpool/src/sound_pool_taihe.cpp index fd6fa55da..9ff2be4c3 100644 --- a/frameworks/taihe/soundpool/src/sound_pool_taihe.cpp +++ b/frameworks/taihe/soundpool/src/sound_pool_taihe.cpp @@ -104,7 +104,7 @@ optional CreateSoundPoolSync(double maxStreams, uintptr_t audioRender return optional(std::in_place, res); } -double SoundPoolImpl::PlaySync(double soundID, optional_view params) +int32_t SoundPoolImpl::PlaySync(int32_t soundID, optional_view params) { MediaTrace trace("SoundPool::TaihePlay"); MEDIA_LOGI("SoundPoolTaihe::TaihePlay"); @@ -125,7 +125,7 @@ double SoundPoolImpl::PlaySync(double soundID, optional_view par return streamId; } -double SoundPoolImpl::PlayWithoutParam(double soundID) +int32_t SoundPoolImpl::PlayWithoutParam(int32_t soundID) { MediaTrace trace("SoundPool::TaihePlayWithoutParam"); MEDIA_LOGI("SoundPoolTaihe::TaihePlayWithoutParam"); @@ -145,7 +145,7 @@ double SoundPoolImpl::PlayWithoutParam(double soundID) return streamId; } -double SoundPoolImpl::PlayWithParam(double soundID, PlayParameters const& params) +int32_t SoundPoolImpl::PlayWithParam(int32_t soundID, PlayParameters const& params) { MediaTrace trace("SoundPool::TaihePlayWithParam"); MEDIA_LOGI("SoundPoolTaihe::TaihePlayWithParam"); @@ -205,7 +205,7 @@ int32_t SoundPoolImpl::ParserPlayOption(const PlayParameters ¶ms) return MSERR_OK; } -double SoundPoolImpl::LoadSync(string_view uri) +int32_t SoundPoolImpl::LoadSync(string_view uri) { MediaTrace trace("SoundPool::TaiheLoad"); MEDIA_LOGI("SoundPoolNapi::TaiheLoad"); @@ -220,7 +220,7 @@ double SoundPoolImpl::LoadSync(string_view uri) return soundId; } -double SoundPoolImpl::LoadWithFdSync(double fd, double offset, double length) +int32_t SoundPoolImpl::LoadWithFdSync(int32_t fd, double offset, double length) { MediaTrace trace("SoundPool::TaiheLoad"); MEDIA_LOGI("SoundPoolNapi::TaiheLoad"); @@ -242,7 +242,7 @@ double SoundPoolImpl::LoadWithFdSync(double fd, double offset, double length) return soundId; } -void SoundPoolImpl::StopSync(double streamID) +void SoundPoolImpl::StopSync(int32_t streamID) { MediaTrace trace("SoundPool::TaiheStop"); MEDIA_LOGI("SoundPoolNapi::TaiheStop"); @@ -258,7 +258,7 @@ void SoundPoolImpl::StopSync(double streamID) MEDIA_LOGI("The taihe thread of stop finishes execution and returns"); } -void SoundPoolImpl::SetLoopSync(double streamID, double loop) +void SoundPoolImpl::SetLoopSync(int32_t streamID, int32_t loop) { MediaTrace trace("SoundPool::TaiheSetLoop"); MEDIA_LOGI("SoundPoolNapi::TaiheSetLoop"); @@ -277,7 +277,7 @@ void SoundPoolImpl::SetLoopSync(double streamID, double loop) } } -void SoundPoolImpl::SetPrioritySync(double streamID, double priority) +void SoundPoolImpl::SetPrioritySync(int32_t streamID, int32_t priority) { MediaTrace trace("SoundPool::TaiheSetPriority"); MEDIA_LOGI("SoundPoolNapi::TaiheSetPriority"); @@ -299,7 +299,27 @@ void SoundPoolImpl::SetPrioritySync(double streamID, double priority) } } -void SoundPoolImpl::SetVolumeSync(double streamID, double leftVolume, double rightVolume) +void SoundPoolImpl::SetRateSync(int32_t streamID, ::ohos::multimedia::audio::AudioRendererRate rate) +{ + MediaTrace trace("SoundPool::TaiheSetRate"); + MEDIA_LOGI("SoundPoolNapi::TaiheSetRate"); + streamId_ = streamID; + if (streamId_ <= 0) { + SignError(MSERR_EXT_API9_INVALID_PARAMETER, "SetPriority streamId failed"); + } + int32_t rendderRate = rate.get_value(); + renderRate_ = static_cast(rendderRate); + if (streamId_ > 0) { + CHECK_AND_RETURN_LOG(soundPool_ != nullptr, "soundPool_ is nullptr!"); + int32_t ret = soundPool_->SetRate(streamId_, renderRate_); + if (ret != MSERR_OK) { + SignError(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "SetRate streamId failed"); + } + MEDIA_LOGI("The taihe thread of SetRate finishes execution and returns"); + } +} + +void SoundPoolImpl::SetVolumeSync(int32_t streamID, double leftVolume, double rightVolume) { MediaTrace trace("SoundPool::TaiheSetVolume"); MEDIA_LOGI("SoundPoolNapi::TaiheSetVolume"); @@ -319,7 +339,7 @@ void SoundPoolImpl::SetVolumeSync(double streamID, double leftVolume, double rig } } -void SoundPoolImpl::UnloadSync(double soundID) +void SoundPoolImpl::UnloadSync(int32_t soundID) { MediaTrace trace("SoundPool::TaiheUnload"); MEDIA_LOGI("SoundPoolNapi::TaiheUnload"); @@ -374,14 +394,14 @@ void SoundPoolImpl::OffError() MEDIA_LOGI("OffError End"); } -void SoundPoolImpl::OnPlayFinishedWithStreamId(callback_view callback) +void SoundPoolImpl::OnPlayFinishedWithStreamId(callback_view callback) { MediaTrace trace("SoundPoolImpl::OnPlayFinishedWithStreamId"); MEDIA_LOGI("OnPlayFinishedWithStreamId Start"); std::string callbackName = SoundPoolEvent::EVENT_PLAY_FINISHED_WITH_STREAM_ID; ani_env *env = get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); @@ -399,14 +419,14 @@ void SoundPoolImpl::OffPlayFinishedWithStreamId() MEDIA_LOGI("OffPlayFinishedWithStreamId End"); } -void SoundPoolImpl::OnLoadComplete(callback_view callback) +void SoundPoolImpl::OnLoadComplete(callback_view callback) { MediaTrace trace("SoundPoolImpl::OnLoadComplete"); MEDIA_LOGI("OnLoadComplete Start"); std::string callbackName = SoundPoolEvent::EVENT_LOAD_COMPLETED; ani_env *env = get_env(); - std::shared_ptr> taiheCallback = - std::make_shared>(callback); + std::shared_ptr> taiheCallback = + std::make_shared>(callback); std::shared_ptr cacheCallback = std::reinterpret_pointer_cast(taiheCallback); std::shared_ptr autoRef = std::make_shared(env, cacheCallback); -- Gitee