/*************************************************************************************** * * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. * * By downloading, copying, installing or using the software you agree to this license. * If you do not agree to this license, do not download, install, * copy or use the software. * * Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved. * * Redistribution and use in binary forms, with or without modification, are permitted. * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific * language governing permissions and limitations under the License. * ****************************************************************************************/ #include "http_mjpeg_player.h" #include "utils.h" /***************************************************************************************/ int http_mjpeg_notify_callback(int evt, void * puser) { CHttpMjpegPlayer * pPlayer = (CHttpMjpegPlayer *) puser; pPlayer->onNotify(evt); return 0; } int http_mjpeg_video_callback(uint8 * pdata, int len, void *puser) { CHttpMjpegPlayer * pPlayer = (CHttpMjpegPlayer *) puser; pPlayer->onVideo(pdata, len, 0); return 0; } /***************************************************************************************/ CHttpMjpegPlayer::CHttpMjpegPlayer(QObject * parent) : CVideoPlayer(parent) { memset(m_ip, 0, sizeof(m_ip)); } CHttpMjpegPlayer::~CHttpMjpegPlayer() { close(); } BOOL CHttpMjpegPlayer::open(QString fileName, WId hWnd) { close(); CVideoPlayer::open(fileName, hWnd); char host[100]; url_split(fileName.toStdString().c_str(), NULL, 0, NULL, 0, NULL, 0, host, sizeof(host), NULL, NULL, 0); if (host[0] == '\0') { return FALSE; } strncpy(m_ip, host, sizeof(m_ip) - 1); m_httpmjpeg.set_notify_cb(http_mjpeg_notify_callback, this); m_httpmjpeg.set_video_cb(http_mjpeg_video_callback); return TRUE; } void CHttpMjpegPlayer::close() { // stop http-mjpeg connection m_httpmjpeg.mjpeg_stop(); m_httpmjpeg.mjpeg_close(); m_bPlaying = FALSE; m_bPaused = FALSE; CVideoPlayer::close(); } BOOL CHttpMjpegPlayer::play() { if (m_httpmjpeg.mjpeg_start(m_sFileName.toStdString().c_str(), m_acct.toStdString().c_str(), m_pass.toStdString().c_str())) { m_bPlaying = TRUE; } return m_bPlaying; } void CHttpMjpegPlayer::stop() { if (m_bPlaying || m_bPaused) { m_httpmjpeg.mjpeg_stop(); } m_bPlaying = FALSE; m_bPaused = FALSE; } BOOL CHttpMjpegPlayer::pause() { return m_bPaused; } BOOL CHttpMjpegPlayer::seek(int pos) { return FALSE; } int CHttpMjpegPlayer::getVideoCodec() { return VIDEO_CODEC_JPEG; } void CHttpMjpegPlayer::onNotify(int evt) { if (evt == MJPEG_EVE_CONNSUCC) { openVideo(VIDEO_CODEC_JPEG); } emit notify(evt); } void CHttpMjpegPlayer::onVideo(uint8 * pdata, int len, uint32 ts) { playVideo(pdata, len, ts, 0); } BOOL CHttpMjpegPlayer::onRecord() { avi_set_video_info(m_pAviCtx, 0, 0, 0, "JPEG"); avi_update_header(m_pAviCtx); return TRUE; } void CHttpMjpegPlayer::onRecordFileSwitch() { AVICTX * p_ctx; AVICTX * p_oldctx = m_pAviCtx; QString path = getRecordPath(); QString file = path + "/" + getTempFile(m_ip, ".avi"); p_ctx = avi_write_open(file.toLocal8Bit().toStdString().c_str()); if (NULL == p_ctx) { return; } p_ctx->ctxf_video = p_oldctx->ctxf_video; if (p_ctx->ctxf_video) { avi_calc_fps(p_oldctx); avi_set_video_info(p_ctx, p_oldctx->v_fps, p_oldctx->v_width, p_oldctx->v_height, p_oldctx->v_fcc); avi_set_video_extra_info(p_ctx, p_oldctx->v_extra, p_oldctx->v_extra_len); } avi_write_close(p_oldctx); avi_update_header(p_ctx); m_pAviCtx = p_ctx; }