2020-05-18 15:31:49 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2020-04-03 20:46:55 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2020-04-03 20:46:55 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
2020-04-03 20:46:55 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_MP4DEMUXER_H
|
|
|
|
|
#define ZLMEDIAKIT_MP4DEMUXER_H
|
|
|
|
|
#ifdef ENABLE_MP4
|
|
|
|
|
#include "MP4.h"
|
|
|
|
|
#include "Extension/Track.h"
|
|
|
|
|
#include "Util/ResourcePool.h"
|
|
|
|
|
namespace mediakit {
|
|
|
|
|
|
2020-09-20 19:45:04 +08:00
|
|
|
|
class MP4Demuxer : public MP4FileDisk, public TrackSource{
|
2020-04-03 20:46:55 +08:00
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<MP4Demuxer> Ptr;
|
2020-09-20 19:45:04 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建mp4解复用器
|
|
|
|
|
*/
|
|
|
|
|
MP4Demuxer();
|
2020-04-03 20:46:55 +08:00
|
|
|
|
~MP4Demuxer() override;
|
2020-09-20 19:45:04 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开文件
|
|
|
|
|
* @param file mp4文件路径
|
|
|
|
|
*/
|
|
|
|
|
void openMP4(const string &file);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 移动时间轴至某处
|
|
|
|
|
* @param stamp_ms 预期的时间轴位置,单位毫秒
|
|
|
|
|
* @return 时间轴位置
|
|
|
|
|
*/
|
2020-04-03 20:46:55 +08:00
|
|
|
|
int64_t seekTo(int64_t stamp_ms);
|
2020-09-20 19:45:04 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取一帧数据
|
|
|
|
|
* @param keyFrame 是否为关键帧
|
|
|
|
|
* @param eof 是否文件读取完毕
|
|
|
|
|
* @return 帧数据,可能为空
|
|
|
|
|
*/
|
2020-04-13 09:44:05 +08:00
|
|
|
|
Frame::Ptr readFrame(bool &keyFrame, bool &eof);
|
2020-09-20 19:45:04 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取所有Track信息
|
|
|
|
|
* @param trackReady 是否要求track为就绪状态
|
|
|
|
|
* @return 所有Track
|
|
|
|
|
*/
|
|
|
|
|
vector<Track::Ptr> getTracks(bool trackReady) const override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取文件长度
|
|
|
|
|
* @return 文件长度,单位毫秒
|
|
|
|
|
*/
|
2020-04-03 20:46:55 +08:00
|
|
|
|
uint64_t getDurationMS() const;
|
2020-09-20 19:45:04 +08:00
|
|
|
|
|
2020-04-03 20:46:55 +08:00
|
|
|
|
private:
|
|
|
|
|
int getAllTracks();
|
2020-09-20 19:45:04 +08:00
|
|
|
|
void onVideoTrack(uint32_t track_id, uint8_t object, int width, int height, const void *extra, size_t bytes);
|
|
|
|
|
void onAudioTrack(uint32_t track_id, uint8_t object, int channel_count, int bit_per_sample, int sample_rate, const void *extra, size_t bytes);
|
|
|
|
|
Frame::Ptr makeFrame(uint32_t track_id, const Buffer::Ptr &buf, int64_t pts, int64_t dts);
|
|
|
|
|
|
2020-04-03 20:46:55 +08:00
|
|
|
|
private:
|
2020-09-20 19:45:04 +08:00
|
|
|
|
Reader _mov_reader;
|
2020-04-03 20:46:55 +08:00
|
|
|
|
uint64_t _duration_ms = 0;
|
2020-09-20 19:45:04 +08:00
|
|
|
|
map<int, Track::Ptr> _track_to_codec;
|
2020-04-03 20:46:55 +08:00
|
|
|
|
ResourcePool<BufferRaw> _buffer_pool;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//namespace mediakit
|
|
|
|
|
#endif//ENABLE_MP4
|
|
|
|
|
#endif //ZLMEDIAKIT_MP4DEMUXER_H
|