[DEV] correct the video display

This commit is contained in:
Edouard DUPIN 2017-06-18 14:01:55 +02:00
parent 0a8dc71521
commit 16fee04656
6 changed files with 28 additions and 33 deletions

View File

@ -101,32 +101,14 @@ static void unPlanar(void* _bufferOut, const void* _bufferIn, int32_t _nbSample,
} }
} }
/**
* @brief get the next power 2 if the input
* @param[in] value Value that we want the next power of 2
* @return result value
*/
static int32_t nextP2(int32_t _value) {
int32_t val=1;
for (int32_t iii=1; iii<31; iii++) {
if (_value <= val) {
return val;
}
val *=2;
}
EWOL_CRITICAL("impossible CASE....");
return val;
}
void appl::MessageElementVideo::setSize(const ivec2& _size) { void appl::MessageElementVideo::setSize(const ivec2& _size) {
if (m_imageRealSize != _size) { if (m_imageRealSize != _size) {
// Resize the buffer: // Resize the buffer:
m_imageRealSize = _size; m_imageRealSize = _size;
m_imagePow2Size = ivec2(nextP2(_size.x()), nextP2(_size.y())); m_lineSize = m_imageRealSize.x() * 3;
m_lineSize = m_imagePow2Size.x() * 3;
} }
if (m_image.getSize() != m_imagePow2Size) { if (m_image.getSize() != m_imageRealSize) {
m_image.resize(m_imagePow2Size); m_image.resize(m_imageRealSize);
} }
} }
void appl::MessageElementAudio::configure(audio::format _format, uint32_t _sampleRate, int32_t _nbChannel, int32_t _nbSample) { void appl::MessageElementAudio::configure(audio::format _format, uint32_t _sampleRate, int32_t _nbChannel, int32_t _nbSample) {
@ -200,9 +182,12 @@ int appl::MediaDecoder::decode_packet(int *_gotFrame, int _cached) {
return ret; return ret;
} }
if (*_gotFrame) { if (*_gotFrame) {
/*
if ( m_frame->width != m_size.x() if ( m_frame->width != m_size.x()
|| m_frame->height != m_size.y() || || m_frame->height != m_size.y()
m_frame->format != m_pixelFormat) { || m_frame->format != m_pixelFormat) {
*/
if (m_frame->format != m_pixelFormat) {
// To handle this change, one could call av_image_alloc again and decode the following frames into another rawvideo file. // To handle this change, one could call av_image_alloc again and decode the following frames into another rawvideo file.
APPL_ERROR("Width, height and pixel format have to be constant in a rawvideo file, but the width, height or pixel format of the input video changed:"); APPL_ERROR("Width, height and pixel format have to be constant in a rawvideo file, but the width, height or pixel format of the input video changed:");
APPL_ERROR("old: size=" << m_size << " format=" << av_get_pix_fmt_name(m_pixelFormat)); APPL_ERROR("old: size=" << m_size << " format=" << av_get_pix_fmt_name(m_pixelFormat));
@ -227,7 +212,8 @@ int appl::MediaDecoder::decode_packet(int *_gotFrame, int _cached) {
if (slotId == -1) { if (slotId == -1) {
APPL_ERROR("an error occured when getting an empty slot for video"); APPL_ERROR("an error occured when getting an empty slot for video");
} else { } else {
m_videoPool[slotId].setSize(ivec2(m_frame->width, m_frame->height)); //m_videoPool[slotId].setSize(ivec2(m_frame->width, m_frame->height));
m_videoPool[slotId].setSize(m_size);
uint8_t* dataPointer = (uint8_t*)(m_videoPool[slotId].m_image.getTextureDataPointer()); uint8_t* dataPointer = (uint8_t*)(m_videoPool[slotId].m_image.getTextureDataPointer());
// Convert Image in RGB: // Convert Image in RGB:
sws_scale(m_convertContext, sws_scale(m_convertContext,
@ -719,12 +705,15 @@ void appl::MediaDecoder::init() {
m_videoDecoderContext = m_videoStream->codec; m_videoDecoderContext = m_videoStream->codec;
// allocate image where the decoded image will be put // allocate image where the decoded image will be put
m_size.setValue(m_videoDecoderContext->width, m_videoDecoderContext->height); m_size.setValue(m_videoDecoderContext->width, m_videoDecoderContext->height);
if (m_size.x() > 512) {
m_size /= 2;
}
m_pixelFormat = m_videoDecoderContext->pix_fmt; m_pixelFormat = m_videoDecoderContext->pix_fmt;
m_videoPool.resize(10); m_videoPool.resize(1);
APPL_INFO("Open video stream with property: size=" << m_size << " pixel format=" << av_get_pix_fmt_name(m_pixelFormat) << " fps=" << getFps(m_videoDecoderContext) << " tick/frame=" << m_videoDecoderContext->ticks_per_frame); APPL_INFO("Open video stream with property: size=" << m_size << " pixel format=" << av_get_pix_fmt_name(m_pixelFormat) << " fps=" << getFps(m_videoDecoderContext) << " tick/frame=" << m_videoDecoderContext->ticks_per_frame);
// convert the image format: // convert the image format:
m_convertContext = sws_getContext(m_size.x(), m_size.y(), m_pixelFormat, m_convertContext = sws_getContext(m_videoDecoderContext->width, m_videoDecoderContext->height, m_pixelFormat,
m_size.x(), m_size.y(), AV_PIX_FMT_RGB24, m_size.x(), m_size.y(), AV_PIX_FMT_RGB24,
0, 0, 0, 0); 0, 0, 0, 0);
} }

View File

@ -41,13 +41,11 @@ namespace appl {
public: public:
egami::Image m_image; //!< Image to manage internal data egami::Image m_image; //!< Image to manage internal data
ivec2 m_imageRealSize; //!< Real size of the image, in OpenGL we need power of 2 border size. ivec2 m_imageRealSize; //!< Real size of the image, in OpenGL we need power of 2 border size.
ivec2 m_imagePow2Size;
int32_t m_lineSize; //!< Size of a single line (in byte) int32_t m_lineSize; //!< Size of a single line (in byte)
void setSize(const ivec2& _newSize); void setSize(const ivec2& _newSize);
MessageElementVideo(): MessageElementVideo():
m_image(ivec2(32,32), egami::colorType::RGB8), m_image(ivec2(32,32), egami::colorType::RGB8),
m_imageRealSize(32,32), m_imageRealSize(32,32) {
m_imagePow2Size(32,32) {
} }
}; };

View File

@ -41,6 +41,7 @@ void appl::widget::Player::init() {
subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-play", signalValue, sharedFromThis(), &appl::widget::Player::onCallbackButtonPlay); subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-play", signalValue, sharedFromThis(), &appl::widget::Player::onCallbackButtonPlay);
subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-next", signalPressed, sharedFromThis(), &appl::widget::Player::onCallbackButtonNext); subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-next", signalPressed, sharedFromThis(), &appl::widget::Player::onCallbackButtonNext);
subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalOther, sharedFromThis(), &appl::widget::Player::onCallbackOther);
subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalPosition, sharedFromThis(), &appl::widget::Player::onCallbackPosition); subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalPosition, sharedFromThis(), &appl::widget::Player::onCallbackPosition);
subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalDuration, sharedFromThis(), &appl::widget::Player::onCallbackDuration); subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalDuration, sharedFromThis(), &appl::widget::Player::onCallbackDuration);
subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalFinish, sharedFromThis(), &appl::widget::Player::onCallbackFinished); subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalFinish, sharedFromThis(), &appl::widget::Player::onCallbackFinished);
@ -174,7 +175,10 @@ void appl::widget::Player::onCallbackLightRequest(const float& _value) {
} }
void appl::widget::Player::onCallbackOther(const std::string& _plop) {
APPL_DEBUG("FPS = " << _plop);
propertySetOnWidgetNamed("[" + etk::to_string(getId()) + "]appl-player-label-fps", "value", "FPS=<font color='orangered'>" + _plop + "</font>");
}
void appl::widget::Player::onCallbackFPS(const int32_t& _fps) { void appl::widget::Player::onCallbackFPS(const int32_t& _fps) {
APPL_DEBUG("FPS = " << _fps); APPL_DEBUG("FPS = " << _fps);

View File

@ -52,6 +52,7 @@ namespace appl {
void onCallbackVolumeRequest(const float& _value); void onCallbackVolumeRequest(const float& _value);
void onCallbackLightRequest(const float& _value); void onCallbackLightRequest(const float& _value);
void onCallbackFPS(const int32_t& _fps); void onCallbackFPS(const int32_t& _fps);
void onCallbackOther(const std::string& _plop);
void onCallbackFinished(); void onCallbackFinished();
}; };
}; };

View File

@ -288,6 +288,7 @@ void appl::widget::VideoDisplay::onRegenerateDisplay() {
} else { } else {
// nothing to display ... // nothing to display ...
} }
markToRedraw();
} }
void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event) { void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event) {
@ -353,14 +354,14 @@ void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event)
// check the slot is valid and check display time of the element: // check the slot is valid and check display time of the element:
if ( idSlot != -1 if ( idSlot != -1
&& m_currentTime > m_decoder->m_videoPool[idSlot].m_time) { && m_currentTime > m_decoder->m_videoPool[idSlot].m_time) {
APPL_VERBOSE("Get Slot VIDEO " << m_currentTime << " > " << m_decoder->m_audioPool[idSlot].m_time); APPL_WARNING("Get Slot VIDEO " << m_currentTime << " > " << m_decoder->m_audioPool[idSlot].m_time);
m_resource[m_useElement]->get().swap(m_decoder->m_videoPool[idSlot].m_image); m_resource[m_useElement]->get().swap(m_decoder->m_videoPool[idSlot].m_image);
m_resource[m_useElement]->flush(); m_resource[m_useElement]->flush();
m_useElement++; m_useElement++;
if (m_useElement == ZEUS_VIDEO_PLAYER_MULTIPLE_BUFFER) { if (m_useElement == ZEUS_VIDEO_PLAYER_MULTIPLE_BUFFER) {
m_useElement = 0; m_useElement = 0;
} }
m_imageSize = m_resource[m_useElement]->get().getSize(); m_imageSize = m_resource[m_useElement]->get().getGPUSize();
ivec2 tmpSize = m_decoder->m_videoPool[idSlot].m_imageRealSize; ivec2 tmpSize = m_decoder->m_videoPool[idSlot].m_imageRealSize;
m_decoder->m_videoPool[idSlot].m_imageRealSize = m_videoSize; m_decoder->m_videoPool[idSlot].m_imageRealSize = m_videoSize;
m_videoSize = tmpSize; m_videoSize = tmpSize;
@ -379,6 +380,7 @@ void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event)
if (m_LastResetCounter > echrono::seconds(1)) { if (m_LastResetCounter > echrono::seconds(1)) {
m_LastResetCounter.reset(); m_LastResetCounter.reset();
signalFps.emit(m_nbFramePushed); signalFps.emit(m_nbFramePushed);
signalOther.emit(std::to_string(m_nbFramePushed) + " " + etk::to_string(m_resource[m_useElement]->get().getSize()) + " " + etk::to_string(m_resource[m_useElement]->get().getGPUSize()) );
m_nbFramePushed = 0; m_nbFramePushed = 0;
} }
if ( getSomething == false if ( getSomething == false

View File

@ -19,12 +19,13 @@
#include <appl/MediaDecoder.hpp> #include <appl/MediaDecoder.hpp>
#include <appl/widget/ListViewer.hpp> #include <appl/widget/ListViewer.hpp>
#define ZEUS_VIDEO_PLAYER_MULTIPLE_BUFFER (4) #define ZEUS_VIDEO_PLAYER_MULTIPLE_BUFFER (1)
namespace appl { namespace appl {
namespace widget { namespace widget {
class VideoDisplay : public ewol::Widget { class VideoDisplay : public ewol::Widget {
public: public:
esignal::Signal<std::string> signalOther;
esignal::Signal<int32_t> signalFps; esignal::Signal<int32_t> signalFps;
esignal::Signal<echrono::Duration> signalPosition; //!< signal the current duration of the video duration esignal::Signal<echrono::Duration> signalPosition; //!< signal the current duration of the video duration
esignal::Signal<echrono::Duration> signalDuration; //!< signal the current duration of the video duration esignal::Signal<echrono::Duration> signalDuration; //!< signal the current duration of the video duration