%bcond_without ESPLUSPLAYER_UT
Name: esplusplayer
Summary: new multimedia streaming player
-Version: 0.0.1
+Version: 0.0.2
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0
std::uint64_t ConvertMsToNs(std::uint64_t ms) {
constexpr std::uint64_t ns_unit = 1000000;
- if (ms * ns_unit > G_MAXUINT64) return G_MAXUINT64;
+ if (ms > (G_MAXUINT64 / ns_unit)) return G_MAXUINT64;
return ms * ns_unit;
}
std::uint64_t ConvertNsToMs(std::uint64_t ns) {
std::int64_t ConvertMsToNs(std::int64_t ms) {
constexpr std::int64_t ns_unit = 1000000;
- if (ms * ns_unit > G_MAXINT64) return G_MAXINT64;
+ if (ms > (G_MAXINT64 / ns_unit)) return G_MAXINT64;
return ms * ns_unit;
}
std::int64_t ConvertNsToMs(std::int64_t ns) {
EsPlayer::~EsPlayer() {
LOG_ENTER_P(this);
- Close();
+ try {
+ Close();
+ } catch (...) {
+ LOG_ERROR("Close failed");
+ }
LOG_LEAVE_P(this);
}
}
}
trackrenderer_->SetTrack(active_track);
- SetTrackRendererAttributes_();
+ try {
+ SetTrackRendererAttributes_();
+ } catch (...) {
+ LOG_ERROR_P(this, "SetTrackRendererAttributes_ failed");
+ return false;
+ }
if (!trackrenderer_->Prepare()) {
return false;
}
virtual void OnMediaPacketVideoDecoded(
const plusplayer::DecodedVideoPacket& packet) {
if (this->media_packet_video_decoded_cb_ == nullptr) return;
+ if (!decoded_pkt_mgr_) return;
auto* _pkt = new esplusplayer_decoded_video_packet();
_pkt->pts = packet.pts;
_pkt->duration = packet.duration;
_pkt->surface_data = static_cast<void*>(packet.surface_data);
_pkt->private_data = packet.buffer_addr;
- if (decoded_pkt_mgr_ && decoded_pkt_mgr_->TryToAdd(_pkt)) {
+
+ if (decoded_pkt_mgr_->TryToAdd(_pkt)) {
this->media_packet_video_decoded_cb_(
_pkt, media_packet_video_decoded_cb_userdata_);
} else {
char** GetCookieList(const char* cookies) {
char **cookie_list = nullptr;
char *temp = nullptr;
+ char *trim = nullptr;
guint i = 0;
if (!cookies || !strlen(cookies))
SECURE_LOG_DEBUG("cookies : %zu[bytes] - %s", strlen(cookies), cookies);
- temp = g_strdup(cookies);
+ trim = temp = g_strdup(cookies);
/* trimming. it works inplace */
- g_strstrip(temp);
+ g_strstrip(trim);
/* split */
- cookie_list = g_strsplit(temp, ";", 100);
+ cookie_list = g_strsplit(trim, ";", 100);
if (!cookie_list) {
LOG_ERROR("failed to get cookie list");
bool SetStreamInfo(esplusplayer_handle& esplayer) {
if (type_ == ESPLUSPLAYER_STREAM_TYPE_AUDIO) {
- esplusplayer_audio_stream_info audio_stream;
+ esplusplayer_audio_stream_info audio_stream = {};
audio_stream.codec_data = nullptr;
audio_stream.codec_data_length = 0;
GetExtraData_(audio_stream.codec_data, audio_stream.codec_data_length);
if (!GetMediaInfo_(audio_stream)) {
if (audio_stream.codec_data != nullptr)
- delete audio_stream.codec_data;
+ delete[] audio_stream.codec_data;
return false;
}
esplusplayer_set_audio_stream_info(esplayer, &audio_stream);
if (audio_stream.codec_data != nullptr)
- delete audio_stream.codec_data;
+ delete[] audio_stream.codec_data;
} else if (type_ == ESPLUSPLAYER_STREAM_TYPE_VIDEO) {
- esplusplayer_video_stream_info video_stream;
+ esplusplayer_video_stream_info video_stream = {};
video_stream.codec_data = nullptr;
video_stream.codec_data_length = 0;
GetExtraData_(video_stream.codec_data, video_stream.codec_data_length);
if (!GetMediaInfo_(video_stream)) {
if (video_stream.codec_data != nullptr)
- delete video_stream.codec_data;
+ delete[] video_stream.codec_data;
return false;
}
esplusplayer_set_video_stream_info(esplayer, &video_stream);
if (video_stream.codec_data != nullptr)
- delete video_stream.codec_data;
+ delete[] video_stream.codec_data;
}
return true;
}
int size = videobytestream2nalunit(tmp);
if (size <= 0) {
+ delete[] tmp;
return false;
- delete tmp;
}
pkt.buffer = new char[size];
int size = audiobytestream2nalunit(tmp);
if (size <= 0) {
+ delete[] tmp;
return false;
- delete tmp;
}
pkt.buffer = new char[size];
pts += ES_DEFAULT_VIDEO_PTS_OFFSET;
}
- delete tmp;
+ delete[] tmp;
return true;
}
class EsBasicTest : public ::testing::TestWithParam<std::string> {
public:
- EsBasicTest() : util_(Utility::Instance()), esplayer_(nullptr) {
- std::cout << "EsBasicTest()" << std::endl; }
+ EsBasicTest() : util_(Utility::Instance()), esplayer_(nullptr), callback_(nullptr),
+ uri_(), video_reader_(nullptr), audio_reader_(nullptr) {
+ std::cout << "EsBasicTest()" << std::endl;
+ }
~EsBasicTest() { std::cout << "~EsBasicTest()" << std::endl; }
static void SetUpTestCase() {
esplusplayer_handle esplayer = esplusplayer_create();
ASSERT_NE(nullptr, esplayer);
ASSERT_EQ(esplusplayer_open(esplayer), ESPLUSPLAYER_ERROR_TYPE_NONE);
- const char* error = new char[100];
- error =
+ std::string error =
esplusplayer_get_error_string(ESPLUSPLAYER_ERROR_TYPE_NOT_SUPPORTED_FILE);
std::cout << "error type" << error << std::endl;
ASSERT_EQ(esplusplayer_close(esplayer), ESPLUSPLAYER_ERROR_TYPE_NONE);
class EsDisplayTest : public ::testing::TestWithParam<std::string> {
public:
- EsDisplayTest(void) : util_(Utility::Instance()), esplayer_(nullptr) {
- std::cout << "EsDisplayTest()" << std::endl; }
+ EsDisplayTest(void) : util_(Utility::Instance()), esplayer_(nullptr), callback_(nullptr),
+ uri_(), video_reader_(nullptr), audio_reader_(nullptr) {
+ std::cout << "EsDisplayTest()" << std::endl;
+ }
~EsDisplayTest() { std::cout << "~EsDisplayTest()" << std::endl; }
static void SetUpTestCase() {
void Utility::FeedingEsPacket(esplusplayer_handle player,
const esplusplayer_stream_type type,
const std::string& uri) {
- EsStreamReader* reader;
+ EsStreamReader* reader = nullptr;
auto feeding_task_fn = [this, &player, &reader]() {
esplusplayer_es_packet pkt;
while (true) {
}
auto feeding_task = std::thread(feeding_task_fn);
if (feeding_task.joinable()) feeding_task.join();
+ if (reader != nullptr) delete reader;
}
void Utility::DestroyESPP(esplusplayer_handle player) {
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
+ try {
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::InitGoogleMock(&argc, argv);
+ } catch (...) {
+ return -1;
+ }
- ::testing::InitGoogleTest(&argc, argv);
- ::testing::InitGoogleMock(&argc, argv);
-
- auto ret = -1;
- ret = RUN_ALL_TESTS();
-
-
- return ret;
+ return RUN_ALL_TESTS();
}