Older/MediaServer/Record/MP4Demuxer.h

110 lines
3.1 KiB
C
Raw Permalink Normal View History

2024-09-28 23:55:00 +08:00
/*
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
*
* Use of this source code is governed by MIT-like 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.
*/
#ifndef ZLMEDIAKIT_MP4DEMUXER_H
#define ZLMEDIAKIT_MP4DEMUXER_H
#ifdef ENABLE_MP4
#include "MP4.h"
#include "Extension/Track.h"
#include "Util/ResourcePool.h"
namespace mediakit {
class MP4Demuxer : public TrackSource {
public:
using Ptr = std::shared_ptr<MP4Demuxer>;
~MP4Demuxer() override;
/**
*
* @param file mp4文件路径
* Open file
* @param file mp4 file path
* [AUTO-TRANSLATED:a64c5a6b]
*/
void openMP4(const std::string &file);
/**
* @brief mp4
* @brief Close mp4 file
* [AUTO-TRANSLATED:527865d9]
*/
void closeMP4();
/**
*
* @param stamp_ms
* @return
* Move timeline to a specific location
* @param stamp_ms Expected timeline position, in milliseconds
* @return Timeline position
* [AUTO-TRANSLATED:51ce0f6d]
*/
int64_t seekTo(int64_t stamp_ms);
/**
*
* @param keyFrame
* @param eof
* @return ,
* Read a frame of data
* @param keyFrame Whether it is a key frame
* @param eof Whether the file has been read completely
* @return Frame data, may be empty
* [AUTO-TRANSLATED:adf550de]
*/
Frame::Ptr readFrame(bool &keyFrame, bool &eof);
/**
* Track信息
* @param trackReady track为就绪状态
* @return Track
* Get all Track information
* @param trackReady Whether to require the track to be ready
* @return All Tracks
* [AUTO-TRANSLATED:c07ad51a]
*/
std::vector<Track::Ptr> getTracks(bool trackReady) const override;
/**
*
* @return
* Get file length
* @return File length, in milliseconds
* [AUTO-TRANSLATED:dcd865d6]
*/
uint64_t getDurationMS() const;
private:
int getAllTracks();
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 toolkit::Buffer::Ptr &buf, int64_t pts, int64_t dts);
private:
MP4FileDisk::Ptr _mp4_file;
MP4FileDisk::Reader _mov_reader;
uint64_t _duration_ms = 0;
std::unordered_map<int, Track::Ptr> _tracks;
toolkit::ResourcePool<toolkit::BufferRaw> _buffer_pool;
};
}//namespace mediakit
#endif//ENABLE_MP4
#endif //ZLMEDIAKIT_MP4DEMUXER_H