修复bug

This commit is contained in:
xiongziliang 2019-08-01 19:09:14 +08:00
parent 383a14a76d
commit 6d8db7d232
3 changed files with 17 additions and 14 deletions

View File

@ -39,7 +39,7 @@ namespace mediakit{
#define ftell64 ftell
#endif
MP4MuxerBase::MP4MuxerBase(int flags) {
void MP4MuxerBase::init(int flags) {
static struct mov_buffer_t s_io = {
[](void* ctx, void* data, uint64_t bytes) {
MP4MuxerBase *thiz = (MP4MuxerBase *)ctx;
@ -67,10 +67,6 @@ MP4MuxerBase::MP4MuxerBase(int flags) {
///////////////////////////////////
MP4Muxer::MP4Muxer(int flags) : MP4MuxerBase(flags) {
}
void MP4Muxer::onTrackFrame(const Frame::Ptr &frame) {
if(frame->configFrame()){
//忽略配置帧
@ -196,15 +192,23 @@ MP4MuxerFile::MP4MuxerFile(const char *file) {
_file.reset(fp,[file_buf](FILE *fp) {
fclose(fp);
});
init(MOV_FLAG_FASTSTART);
}
MP4MuxerFile::~MP4MuxerFile() {
_mov_writter = nullptr;
}
int MP4MuxerFile::onRead(void *data, uint64_t bytes) {
return fread(data, 1, bytes, _file.get());
if (bytes == fread(data, 1, bytes, _file.get())){
return 0;
}
return 0 != ferror(_file.get()) ? ferror(_file.get()) : -1 /*EOF*/;
}
int MP4MuxerFile::onWrite(const void *data, uint64_t bytes) {
return fwrite(data, 1, bytes, _file.get());
return bytes == fwrite(data, 1, bytes, _file.get()) ? 0 : ferror(_file.get());
}
@ -224,7 +228,6 @@ uint64_t MP4MuxerFile::onTell() {
return ftell64(_file.get());
}
}//namespace mediakit
#endif//#ifdef ENABLE_MP4RECORD

View File

@ -44,20 +44,21 @@ namespace mediakit{
class MP4MuxerBase{
public:
MP4MuxerBase(int flags = MOV_FLAG_FASTSTART);
MP4MuxerBase() = default;
virtual ~MP4MuxerBase() = default;
protected:
virtual int onRead(void* data, uint64_t bytes) = 0;
virtual int onWrite(const void* data, uint64_t bytes) = 0;
virtual int onSeek( uint64_t offset) = 0;
virtual uint64_t onTell() = 0;
void init(int flags);
protected:
std::shared_ptr<mov_writer_t> _mov_writter;
};
class MP4Muxer : public MediaSink , public MP4MuxerBase{
public:
MP4Muxer(int flags = MOV_FLAG_FASTSTART) ;
MP4Muxer() = default;
~MP4Muxer() override = default;
protected:
/**
@ -81,7 +82,7 @@ class MP4MuxerFile : public MP4Muxer {
public:
typedef std::shared_ptr<MP4MuxerFile> Ptr;
MP4MuxerFile(const char *file);
~MP4MuxerFile() = default;
~MP4MuxerFile();
protected:
int onRead(void* data, uint64_t bytes) override;
int onWrite(const void* data, uint64_t bytes) override;

View File

@ -239,8 +239,7 @@ int main(int argc,char *argv[]) {
//这里是拉流地址支持rtmp/rtsp协议负载必须是H264+AAC
//如果是其他不识别的音视频将会被忽略(譬如说h264+adpcm转发后会去除音频)
auto urlList = {"rtmp://live.hkstv.hk.lxdns.com/live/hks1",
"rtmp://live.hkstv.hk.lxdns.com/live/hks2"
auto urlList = {"rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"
//rtsp链接支持输入用户名密码
/*"rtsp://admin:jzan123456@192.168.0.122/"*/};
map<string, PlayerProxy::Ptr> proxyMap;
@ -259,7 +258,7 @@ int main(int argc,char *argv[]) {
//rtsp://127.0.0.1/record/live/0/2017-04-11/11-09-38.mp4
//rtmp://127.0.0.1/record/live/0/2017-04-11/11-09-38.mp4
PlayerProxy::Ptr player(new PlayerProxy(DEFAULT_VHOST, "live", to_string(i).data()));
PlayerProxy::Ptr player(new PlayerProxy(DEFAULT_VHOST, "live", to_string(i).data(),false,false,false,true));
//指定RTP over TCP(播放rtsp时有效)
(*player)[kRtpType] = Rtsp::RTP_TCP;
//开始播放,如果播放失败或者播放中止,将会自动重试若干次,重试次数在配置文件中配置,默认一直重试