mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
fixed compiling on linux
This commit is contained in:
parent
7ae4b39574
commit
ab9e716444
|
@ -8,16 +8,8 @@
|
||||||
|
|
||||||
// This code is mostly stolen from https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/muxing.c
|
// This code is mostly stolen from https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/muxing.c
|
||||||
|
|
||||||
#define STREAM_FRAME_RATE 60 /* 60 images/s */
|
|
||||||
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
|
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
|
||||||
|
|
||||||
IVideo* IVideo::ms_pCurrentVideo = 0;
|
|
||||||
|
|
||||||
int64 IVideo::ms_Time = 0;
|
|
||||||
float IVideo::ms_LocalTime = 0;
|
|
||||||
int64 IVideo::ms_LocalStartTime = 0;
|
|
||||||
int64 IVideo::ms_TickTime = time_freq() / STREAM_FRAME_RATE;
|
|
||||||
|
|
||||||
CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pConsole, int width, int height) :
|
CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pConsole, int width, int height) :
|
||||||
IVideo::IVideo(),
|
IVideo::IVideo(),
|
||||||
m_pGraphics(pGraphics),
|
m_pGraphics(pGraphics),
|
||||||
|
@ -47,7 +39,7 @@ CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pCon
|
||||||
m_NextFrame = false;
|
m_NextFrame = false;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
m_HasAudio = false;
|
m_HasAudio = true;
|
||||||
|
|
||||||
m_SndBufferSize = g_Config.m_SndBufferSize;
|
m_SndBufferSize = g_Config.m_SndBufferSize;
|
||||||
|
|
||||||
|
@ -123,8 +115,9 @@ void CVideo::start()
|
||||||
int ret = avio_open(&m_pFormatContext->pb, aWholePath, AVIO_FLAG_WRITE);
|
int ret = avio_open(&m_pFormatContext->pb, aWholePath, AVIO_FLAG_WRITE);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
dbg_msg("video_recorder", "Could not open '%s': %s", aWholePath,
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
av_err2str(ret));
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
|
dbg_msg("video_recorder", "Could not open '%s': %s", aWholePath, aBuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +127,9 @@ void CVideo::start()
|
||||||
int ret = avformat_write_header(m_pFormatContext, &m_pOptDict);
|
int ret = avformat_write_header(m_pFormatContext, &m_pOptDict);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
dbg_msg("video_recorder", "Error occurred when opening output file: %s", av_err2str(ret));
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
|
dbg_msg("video_recorder", "Error occurred when opening output file: %s", aBuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Recording = true;
|
m_Recording = true;
|
||||||
|
@ -226,7 +221,7 @@ void CVideo::nextAudioFrame(short* pData)
|
||||||
m_AudioStream.frame->pts = m_AudioStream.enc->frame_number;
|
m_AudioStream.frame->pts = m_AudioStream.enc->frame_number;
|
||||||
// dbg_msg("video_recorder", "aframe: %d", m_AudioStream.enc->frame_number);
|
// dbg_msg("video_recorder", "aframe: %d", m_AudioStream.enc->frame_number);
|
||||||
|
|
||||||
memcpy(m_AudioStream.tmp_frame->data[0], pData, sizeof(int16_t) * m_SndBufferSize * 2);
|
// memcpy(m_AudioStream.tmp_frame->data[0], pData, sizeof(int16_t) * m_SndBufferSize * 2);
|
||||||
//
|
//
|
||||||
// for (int i = 0; i < m_SndBufferSize; i++)
|
// for (int i = 0; i < m_SndBufferSize; i++)
|
||||||
// {
|
// {
|
||||||
|
@ -247,6 +242,16 @@ void CVideo::nextAudioFrame(short* pData)
|
||||||
|
|
||||||
// dbg_msg("video_recorder", "dst_nb_samples: %d", dst_nb_samples);
|
// dbg_msg("video_recorder", "dst_nb_samples: %d", dst_nb_samples);
|
||||||
|
|
||||||
|
av_samples_fill_arrays(
|
||||||
|
(uint8_t**)m_AudioStream.tmp_frame->data,
|
||||||
|
0, // pointer to linesize (int*)
|
||||||
|
(const uint8_t*)pData,
|
||||||
|
2, // channels
|
||||||
|
m_AudioStream.tmp_frame->nb_samples,
|
||||||
|
AV_SAMPLE_FMT_S16P,
|
||||||
|
0 // align
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
int ret = av_frame_make_writable(m_AudioStream.frame);
|
int ret = av_frame_make_writable(m_AudioStream.frame);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -386,7 +391,9 @@ void CVideo::open_video()
|
||||||
av_dict_free(&opt);
|
av_dict_free(&opt);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
dbg_msg("video_recorder", "Could not open video codec: %s", av_err2str(ret));
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
|
dbg_msg("video_recorder", "Could not open video codec: %s", aBuf);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,8 +442,11 @@ void CVideo::open_audio()
|
||||||
av_dict_copy(&opt, m_pOptDict, 0);
|
av_dict_copy(&opt, m_pOptDict, 0);
|
||||||
ret = avcodec_open2(c, m_AudioCodec, &opt);
|
ret = avcodec_open2(c, m_AudioCodec, &opt);
|
||||||
av_dict_free(&opt);
|
av_dict_free(&opt);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
dbg_msg("video_recorder", "Could not open audio codec: %s", av_err2str(ret));
|
{
|
||||||
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
|
dbg_msg("video_recorder", "Could not open audio codec: %s", aBuf);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,7 +620,9 @@ void CVideo::write_frame(OutputStream* pStream)
|
||||||
|
|
||||||
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
|
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
|
||||||
{
|
{
|
||||||
dbg_msg("video_recorder", "Error while writing video frame: %s", av_err2str(ret));
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
|
dbg_msg("video_recorder", "Error while writing video frame: %s", aBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -646,7 +658,9 @@ void CVideo::finish_frames(OutputStream* pStream)
|
||||||
|
|
||||||
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
|
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
|
||||||
{
|
{
|
||||||
dbg_msg("video_recorder", "Error while writing video frame: %s", av_err2str(ret));
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
|
dbg_msg("video_recorder", "Error while writing video frame: %s", aBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
12
src/engine/shared/video.cpp
Normal file
12
src/engine/shared/video.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#if defined(CONF_VIDEORECORDER)
|
||||||
|
|
||||||
|
#include "video.h"
|
||||||
|
|
||||||
|
IVideo* IVideo::ms_pCurrentVideo = 0;
|
||||||
|
|
||||||
|
int64 IVideo::ms_Time = 0;
|
||||||
|
float IVideo::ms_LocalTime = 0;
|
||||||
|
int64 IVideo::ms_LocalStartTime = 0;
|
||||||
|
int64 IVideo::ms_TickTime = time_freq() / STREAM_FRAME_RATE;
|
||||||
|
|
||||||
|
#endif
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <base/system.h>
|
#include <base/system.h>
|
||||||
|
|
||||||
|
#define STREAM_FRAME_RATE 60 /* 60 images/s */
|
||||||
|
|
||||||
class IVideo
|
class IVideo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue