/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this mFileAudio except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "RecordMp4.h" #include "ILog.h" #include "IMediaManager.h" #include "MediaBase.h" #include "StatusCode.h" #include #include #include #include #include #include RecordMp4::RecordMp4(std::shared_ptr &recordTask) : mRecordMp4Object(nullptr), mRecordTask(recordTask) { } StatusCode RecordMp4::Init(void) { mRecordMp4Object = ICreateMediaBase(MEDIA_HANDLE_TYPE_COMBINE_MP4); if (nullptr == mRecordMp4Object) { LogError("mRecordMp4Object is null.\n"); return CreateStatusCode(STATUS_CODE_NOT_OK); } std::string videoPath = mRecordTask->GetTargetNameForSaving(); StatusCode code = IOpenOutputFile(mRecordMp4Object, videoPath.c_str()); if (!IsCodeOK(code)) { LogError("OpenOutputFile failed.\n"); ICloseOutputFile(mRecordMp4Object); IMediaBaseFree(mRecordMp4Object); mRecordMp4Object = nullptr; } return code; } StatusCode RecordMp4::UnInit(void) { StopHandleStream(); return CreateStatusCode(STATUS_CODE_OK); } void RecordMp4::StopHandleStream(void) { std::lock_guard locker(mMutex); if (mRecordMp4Object) { ICloseOutputFile(mRecordMp4Object); IMediaBaseFree(mRecordMp4Object); mRecordMp4Object = nullptr; } std::string videoPath = mRecordTask->GetTargetNameForSaving(); MediaTaskResponse response(videoPath.c_str()); mTaskResponse.push_back(response); } void RecordMp4::GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp) { std::lock_guard locker(mMutex); if (mRecordMp4Object) { StreamInfo info = {.mType = STREAM_TYPE_VIDEO_H264}; IGetStreamData(mRecordMp4Object, stream, length, info); } } void RecordMp4::GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp) { std::lock_guard locker(mMutex); if (mRecordMp4Object) { StreamInfo info = {.mType = STREAM_TYPE_AUDIO_G711A}; IGetStreamData(mRecordMp4Object, stream, length, info); } } StatusCode RecordMp4::GetAllFiles(std::vector &files) { files = std::move(mTaskResponse); mTaskResponse.clear(); return CreateStatusCode(STATUS_CODE_OK); }