ZLMediaKit/src/Http/TsplayerImp.cpp

51 lines
1.6 KiB
C++
Raw Normal View History

2022-01-09 15:01:23 +08:00
/*
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
* Created by alex on 2021/4/6.
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* 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.
*/
2022-01-04 15:32:59 +08:00
#include "TsPlayerImp.h"
2022-01-20 14:48:45 +08:00
#include "HlsPlayer.h"
2022-01-04 15:32:59 +08:00
namespace mediakit {
2022-01-09 15:01:23 +08:00
TsPlayerImp::TsPlayerImp(const EventPoller::Ptr &poller) : PlayerImp<TsPlayer, PlayerBase>(poller) {}
2022-01-04 15:32:59 +08:00
2022-01-09 15:01:23 +08:00
void TsPlayerImp::onPacket(const char *data, size_t len) {
2022-01-20 14:48:45 +08:00
if (!_decoder && _demuxer) {
2022-01-09 15:01:23 +08:00
_decoder = DecoderImp::createDecoder(DecoderImp::decoder_ts, _demuxer.get());
2022-01-04 15:32:59 +08:00
}
2022-01-09 15:01:23 +08:00
if (_decoder && _demuxer) {
_decoder->input((uint8_t *) data, len);
2022-01-04 15:32:59 +08:00
}
2022-01-09 15:01:23 +08:00
}
void TsPlayerImp::addTrackCompleted() {
2022-01-20 14:48:45 +08:00
PlayerImp<TsPlayer, PlayerBase>::onPlayResult(SockException(Err_success, "play http-ts success"));
2022-01-09 15:01:23 +08:00
}
void TsPlayerImp::onPlayResult(const SockException &ex) {
if (ex) {
PlayerImp<TsPlayer, PlayerBase>::onPlayResult(ex);
} else {
2022-01-20 14:48:45 +08:00
auto demuxer = std::make_shared<HlsDemuxer>();
2022-01-09 15:01:23 +08:00
demuxer->start(getPoller(), this);
_demuxer = std::move(demuxer);
2022-01-04 15:32:59 +08:00
}
2022-01-09 15:01:23 +08:00
}
2022-01-04 15:32:59 +08:00
2022-01-09 15:01:23 +08:00
void TsPlayerImp::onShutdown(const SockException &ex) {
PlayerImp<TsPlayer, PlayerBase>::onShutdown(ex);
_demuxer = nullptr;
}
2022-01-04 15:32:59 +08:00
2022-01-09 15:01:23 +08:00
vector <Track::Ptr> TsPlayerImp::getTracks(bool ready) const {
2022-01-20 14:48:45 +08:00
return static_pointer_cast<HlsDemuxer>(_demuxer)->getTracks(ready);
2022-01-09 15:01:23 +08:00
}
2022-01-04 15:32:59 +08:00
}//namespace mediakit