1/* 2 * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "common.h" 17 18namespace OHOS { 19namespace Sharing { 20 21#define VIDEO_RESOLUTION_640 640 22#define VIDEO_RESOLUTION_480 480 23#define VIDEO_RESOLUTION_1280 1280 24#define VIDEO_RESOLUTION_720 720 25#define VIDEO_RESOLUTION_1920 1920 26#define VIDEO_RESOLUTION_1080 1080 27 28#define VIDEO_FRAME_RATE_60 60 29#define VIDEO_FRAME_RATE_25 25 30#define VIDEO_FRAME_RATE_30 30 31 32#define AUDIO_SAMPLE_BIT 16 33#define AUDIO_SAMEPLE_CHANNEL 2 34 35void Common::SetVideoTrack(VideoTrack &videoTrack, VideoFormat videoFormat) 36{ 37 switch (videoFormat) { 38 case VideoFormat::VIDEO_640X480_60: 39 videoTrack.codecId = CodecId::CODEC_H264; 40 videoTrack.width = VIDEO_RESOLUTION_640; 41 videoTrack.height = VIDEO_RESOLUTION_480; 42 videoTrack.frameRate = VIDEO_FRAME_RATE_60; 43 break; 44 case VideoFormat::VIDEO_1280X720_25: 45 videoTrack.codecId = CodecId::CODEC_H264; 46 videoTrack.width = VIDEO_RESOLUTION_1280; 47 videoTrack.height = VIDEO_RESOLUTION_720; 48 videoTrack.frameRate = VIDEO_FRAME_RATE_25; 49 break; 50 case VideoFormat::VIDEO_1280X720_30: 51 videoTrack.codecId = CodecId::CODEC_H264; 52 videoTrack.width = VIDEO_RESOLUTION_1280; 53 videoTrack.height = VIDEO_RESOLUTION_720; 54 videoTrack.frameRate = VIDEO_FRAME_RATE_30; 55 break; 56 case VideoFormat::VIDEO_1920X1080_25: 57 videoTrack.codecId = CodecId::CODEC_H264; 58 videoTrack.width = VIDEO_RESOLUTION_1920; 59 videoTrack.height = VIDEO_RESOLUTION_1080; 60 videoTrack.frameRate = VIDEO_FRAME_RATE_25; 61 break; 62 case VideoFormat::VIDEO_1920X1080_30: 63 videoTrack.codecId = CodecId::CODEC_H264; 64 videoTrack.width = VIDEO_RESOLUTION_1920; 65 videoTrack.height = VIDEO_RESOLUTION_1080; 66 videoTrack.frameRate = VIDEO_FRAME_RATE_30; 67 break; 68 default: 69 SHARING_LOGI("none process case."); 70 break; 71 } 72} 73 74void Common::SetAudioTrack(AudioTrack &audioTrack, AudioFormat audioFormat) 75{ 76 SetAudioTrack(audioTrack, CodecId::CODEC_AAC, audioFormat); 77} 78 79void Common::SetAudioTrack(AudioTrack &audioTrack, CodecId codecId, AudioFormat audioFormat) 80{ 81 switch (audioFormat) { 82 case AudioFormat::AUDIO_44100_8_2: 83 case AudioFormat::AUDIO_44100_16_2: 84 audioTrack.codecId = codecId; 85 audioTrack.sampleRate = AUDIO_SAMPLE_RATE_44100; 86 audioTrack.sampleBit = AUDIO_SAMPLE_BIT; 87 audioTrack.channels = AUDIO_SAMEPLE_CHANNEL; 88 break; 89 case AudioFormat::AUDIO_48000_16_2: 90 audioTrack.codecId = codecId; 91 audioTrack.sampleRate = AUDIO_SAMPLE_RATE_48000; 92 audioTrack.sampleBit = AUDIO_SAMPLE_BIT; 93 audioTrack.channels = AUDIO_SAMEPLE_CHANNEL; 94 break; 95 default: 96 SHARING_LOGI("none process case."); 97 break; 98 } 99} 100} // namespace Sharing 101} // namespace OHOS