mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-12-11 17:16:02 +00:00
!5 增加 ffmpeg_demuxer_plugin 功能接口、OH_AVCodecBufferAttr增加trackId字段
Merge pull request !5 from 杨俊晖/dev_yjh_v2
This commit is contained in:
commit
9bef8b5eab
@ -56,6 +56,8 @@ struct AVCodecBufferInfo {
|
||||
int32_t offset = 0;
|
||||
/* The flag of the available buffer. For details, see {@link AVCodecBufferFlag} */
|
||||
uint32_t flags = 0;
|
||||
/* The index of the track which this Buffer belongs. */
|
||||
uint32_t trackId;
|
||||
};
|
||||
|
||||
struct AVBufferElement {
|
||||
|
@ -79,6 +79,8 @@ typedef struct OH_AVCodecBufferAttr {
|
||||
int32_t offset;
|
||||
/* The flags this Buffer has, which is also a combination of multiple {@link OH_AVCodecBufferFlags}. */
|
||||
uint32_t flags;
|
||||
/* The index of the track which this Buffer belongs. */
|
||||
uint32_t trackId;
|
||||
} OH_AVCodecBufferAttr;
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ffmpeg_demuxer_plugin.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "FFmpegDemuxerPlugin"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec{
|
||||
namespace Plugin {
|
||||
namespace Ffmpeg {
|
||||
Status FFmpegDemuxerPlugin::AddSourceTrackByID(uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(formatContext_ != nullptr,
|
||||
ErrCode::AVCSERR_DEMUXER_FAILED, "formatContext_ is empty!");
|
||||
CHECK_AND_RETURN_RET_LOG(trackId > 0 && trackId < static_cast<int32_t>(formatContext_->nb_streames),
|
||||
ErrCode::AVCSERR_INVALID_VAL, "trackId is invalid!");
|
||||
|
||||
OSAL::ScopedLock lock(mutex_);
|
||||
auto index = std::find_if(selectedTrackIds_.begin(), selectedTrackIds_.end(),
|
||||
[trackId](int32_t selectedId) {return trackId == selectedId; });
|
||||
if (index == selectedTrackIds_.end()) {
|
||||
selectedTrackIds_.push_back(trackId);
|
||||
}
|
||||
return ErrCode::AVCSERR_OK;
|
||||
}
|
||||
|
||||
Status FFmpegDemuxerPlugin::RemoveSourceTrackByID(uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(formatContext_ != nullptr, Status::ERROR_NULL_POINTER, "formatContext_ is empty");
|
||||
|
||||
OSAL::ScopedLock lock(mutex_);
|
||||
auto index = find_if(selectedTrackIds_.begin(), selectedTrackIds_.end(),
|
||||
[trackId](int32_t selectedId) {return trackId == selectedId; });
|
||||
if (index != selectedTrackIds_.end()) {
|
||||
selectedTrackIds_.erase(index);
|
||||
}
|
||||
|
||||
return ErrCode::AVCSERR_OK;
|
||||
}
|
||||
|
||||
} // Ffmpeg
|
||||
} // Plugin
|
||||
} // Media
|
||||
} // OHOS
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_DEMUXER_PLUGIN_H
|
||||
#define FFMPEG_DEMUXER_PLUGIN_H
|
||||
|
||||
#include <memory>
|
||||
#include <stdint>
|
||||
#include <vector>
|
||||
#include "avcodec_common.h"
|
||||
#include "demuxer_plugin.h"
|
||||
#include "plugin/osal/thread/mutex.h"
|
||||
#include "source.h"
|
||||
#include "libavformat/avformat.h"
|
||||
|
||||
namespace OH{
|
||||
namespace AVCodec{
|
||||
namespace Plugin{
|
||||
namespace FFmpeg{
|
||||
class FFmpegDemuxerPlugin : public DemuxerPlugin{
|
||||
public:
|
||||
FFmpegDemuxerPlugin(Source source);
|
||||
~FFmpegDemuxerPlugin() override;
|
||||
|
||||
Status AddSourceTrackByID(uint32_t index) override;
|
||||
Status RemoveSourceTrackByID(uint32_t index) override;
|
||||
Status CopyCurrentSampleToBuf(AVCodecBufferElement *buffer, AVCodecBufferInfo *bufferInfo) override;
|
||||
Status SeekToTimeStamp(int64_t mSeconds, SeekMode mode) override;
|
||||
private:
|
||||
vector<int32_t> selectedTrackIds_;
|
||||
OSAL::Mutex mutex_ {};
|
||||
std::shared_ptr<AVFormatContext> formatContext_;
|
||||
};
|
||||
} // namespace FFmpeg
|
||||
} // namespace Plugin
|
||||
} // namespace AVCodec
|
||||
} // namespace OH
|
||||
#endif // FFMPEG_DEMUXER_PLUGIN_H
|
Loading…
Reference in New Issue
Block a user