[vlmc-devel] VideoClipWorkflow: Account for potential frame borders
Hugo Beauzée-Luyssen
git at videolan.org
Tue Jan 28 23:33:35 CET 2014
vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Jan 29 00:20:37 2014 +0200| [e1d42a44aae9bf9c1cd208051ec1ae0facff1dbe] | committer: Hugo Beauzée-Luyssen
VideoClipWorkflow: Account for potential frame borders
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=e1d42a44aae9bf9c1cd208051ec1ae0facff1dbe
---
src/Workflow/Types.cpp | 33 ++++++++++++++++++++++++---------
src/Workflow/Types.h | 24 ++++++++++++++++++++----
src/Workflow/VideoClipWorkflow.cpp | 13 +++++++++++--
3 files changed, 55 insertions(+), 15 deletions(-)
diff --git a/src/Workflow/Types.cpp b/src/Workflow/Types.cpp
index a75eef4..86e8d21 100644
--- a/src/Workflow/Types.cpp
+++ b/src/Workflow/Types.cpp
@@ -48,6 +48,18 @@ Frame::Frame( quint32 width, quint32 height ) :
m_buffer = new quint32[m_nbPixels];
}
+Frame::Frame(quint32 width, quint32 height, size_t forcedSize) :
+ OutputBuffer( VideoTrack ),
+ ptsDiff( 0 ),
+ m_width( width ),
+ m_height( height )
+{
+ m_nbPixels = width * height;
+ m_size = forcedSize;
+ Q_ASSERT(forcedSize % 4 == 0);
+ m_buffer = new quint32[forcedSize / 4];
+}
+
Frame::~Frame()
{
delete[] m_buffer;
@@ -59,8 +71,7 @@ Frame::buffer()
return m_buffer;
}
-const quint32*
-Frame::buffer() const
+const quint32 *Frame::buffer() const
{
return m_buffer;
}
@@ -77,8 +88,7 @@ Frame::height() const
return m_height;
}
-quint32
-Frame::size() const
+size_t Frame::size() const
{
return m_size;
}
@@ -89,12 +99,9 @@ Frame::nbPixels() const
return m_nbPixels;
}
-Frame*
-Frame::clone() const
+size_t Frame::Size(quint32 width, quint32 height)
{
- Frame *f = new Frame( m_width, m_height );
- memcpy( f->buffer(), m_buffer, m_size );
- return f;
+ return width * height * Depth;
}
void
@@ -117,3 +124,11 @@ Frame::resize( quint32 width, quint32 height )
m_buffer = new quint32[m_nbPixels];
}
}
+
+void Frame::resize(size_t size)
+{
+ if ( size == m_size )
+ return ;
+ delete[] m_buffer;
+ m_buffer = new quint32[size];
+}
diff --git a/src/Workflow/Types.h b/src/Workflow/Types.h
index cd52fc0..b0de5c9 100644
--- a/src/Workflow/Types.h
+++ b/src/Workflow/Types.h
@@ -27,6 +27,7 @@
namespace Workflow
{
+ // This is constrained by frei0r
const quint32 Depth = 4;
/**
@@ -51,30 +52,37 @@ namespace Workflow
public:
explicit Frame();
Frame( quint32 width, quint32 height );
+ Frame( quint32 width, quint32 height, size_t forcedSize );
~Frame();
quint32 width() const;
quint32 height() const;
quint32 *buffer();
const quint32 *buffer() const;
void setBuffer( quint32 *buff );
- Frame *clone() const;
/**
* \brief Resize the buffer.
*
- * \warning This will not resize what's in the frame !
+ * \warning This will not resize what's in the frame but drop it instead!
*/
void resize( quint32 width, quint32 height );
/**
+ * \brief Resize the buffer
+ *
+ * This will allocate a new buffer and drop the old one.
+ * \param size The size, in bytes.
+ */
+ void resize( size_t size );
+ /**
* \returns The frame size in octets
*
* This is equal to width * height * Depth
*/
+ size_t size() const;
/**
* \returns The frame size in pixels
*
* This is equal to width * height
*/
- quint32 size() const;
quint32 nbPixels() const;
/**
* \warning Terrible hack !
@@ -83,11 +91,19 @@ namespace Workflow
*/
//FIXME
qint64 ptsDiff;
+
+ public:
+ /**
+ * @brief Size Computes the size, in bytes, a frame with given dimension would use.
+ */
+ static size_t Size( quint32 width, quint32 height );
+
private:
quint32 m_width;
quint32 m_height;
+ // frei0r uses 32bits only pixels, and expects its buffers as uint32
quint32 *m_buffer;
- quint32 m_size;
+ size_t m_size;
quint32 m_nbPixels;
};
class AudioSample : public OutputBuffer
diff --git a/src/Workflow/VideoClipWorkflow.cpp b/src/Workflow/VideoClipWorkflow.cpp
index 1cae3c1..71cc12e 100644
--- a/src/Workflow/VideoClipWorkflow.cpp
+++ b/src/Workflow/VideoClipWorkflow.cpp
@@ -158,14 +158,23 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode, qint64 currentFrame )
void
VideoClipWorkflow::lock( VideoClipWorkflow *cw, void **pp_ret, int size )
{
- Q_UNUSED( size );
+ //Mind the fact that frame size in bytes might not be width * height * bpp
Workflow::Frame* frame = NULL;
cw->m_renderLock->lock();
if ( cw->m_availableBuffers.isEmpty() == true )
- frame = new Workflow::Frame( cw->m_width, cw->m_height );
+ {
+ if ( Workflow::Frame::Size( cw->m_width, cw->m_height ) == size )
+ frame = new Workflow::Frame( cw->m_width, cw->m_height );
+ else
+ frame = new Workflow::Frame( cw->m_width, cw->m_height, size );
+ }
else
+ {
frame = cw->m_availableBuffers.dequeue();
+ if ( frame->size() != size )
+ frame->resize( size );
+ }
cw->m_computedBuffers.enqueue( frame );
*pp_ret = frame->buffer();
}
More information about the Vlmc-devel
mailing list