[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/asobj/xmlsocket.cpp serv...
From: |
Bastiaan Jacques |
Subject: |
[Gnash-commit] gnash ChangeLog server/asobj/xmlsocket.cpp serv... |
Date: |
Tue, 10 Apr 2007 20:24:23 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Bastiaan Jacques <bjacques> 07/04/10 20:24:23
Modified files:
. : ChangeLog
server/asobj : xmlsocket.cpp NetStreamFfmpeg.cpp
NetStreamFfmpeg.h
libbase : image.cpp
Log message:
* server/asobj/NetStreamFfmpeg.{cpp,h}: Don't call delete on a
new[]-allocated pointer. Don't try to copy a byte-aligned
data buffer into a "flat" one, and vice versa. Add a helper
class called AudioResampler, which will do audio resampling
if necessary.
* server/xmlsocket.cpp: Use SIZET_FMT.
* libbase/image.cpp: Document update().
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2830&r2=1.2831
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.cpp?cvsroot=gnash&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.h?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/image.cpp?cvsroot=gnash&r1=1.17&r2=1.18
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2830
retrieving revision 1.2831
diff -u -b -r1.2830 -r1.2831
--- ChangeLog 10 Apr 2007 18:18:45 -0000 1.2830
+++ ChangeLog 10 Apr 2007 20:24:22 -0000 1.2831
@@ -1,3 +1,13 @@
+2007-04-10 Bastiaan Jacques <address@hidden>
+
+ * server/asobj/NetStreamFfmpeg.{cpp,h}: Don't call delete on a
+ new[]-allocated pointer. Don't try to copy a byte-aligned
+ data buffer into a "flat" one, and vice versa. Add a helper
+ class called AudioResampler, which will do audio resampling
+ if necessary.
+ * server/xmlsocket.cpp: Use SIZET_FMT.
+ * libbase/image.cpp: Document update().
+
2007-04-10 Rob Savoye <address@hidden>
* configure.ac: Test the host to see if we're on a Darwin machine.
Index: server/asobj/xmlsocket.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- server/asobj/xmlsocket.cpp 5 Apr 2007 07:31:28 -0000 1.23
+++ server/asobj/xmlsocket.cpp 10 Apr 2007 20:24:23 -0000 1.24
@@ -659,10 +659,10 @@
std::vector<std::string > msgs;
if (obj.anydata(msgs))
{
- log_msg("Got %u messages: ", msgs.size());
+ log_msg("Got " SIZET_FMT " messages: ", msgs.size());
for (size_t i=0; i<msgs.size(); ++i)
{
- log_msg(" Message %u: %s ", i, msgs[i].c_str());
+ log_msg(" Message " SIZET_FMT " : %s ", i, msgs[i].c_str());
}
boost::intrusive_ptr<as_function> onDataHandler =
getEventHandler("onData");
Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- server/asobj/NetStreamFfmpeg.cpp 8 Apr 2007 15:23:43 -0000 1.34
+++ server/asobj/NetStreamFfmpeg.cpp 10 Apr 2007 20:24:23 -0000 1.35
@@ -14,7 +14,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-/* $Id: NetStreamFfmpeg.cpp,v 1.34 2007/04/08 15:23:43 bjacques Exp $ */
+/* $Id: NetStreamFfmpeg.cpp,v 1.35 2007/04/10 20:24:23 bjacques Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -42,7 +42,7 @@
// Used to free data in the AVPackets we create our self
static void avpacket_destruct(AVPacket* av) {
- delete av->data;
+ delete [] av->data;
}
@@ -57,7 +57,6 @@
m_ACodecCtx(NULL),
m_FormatCtx(NULL),
m_Frame(NULL),
- m_Resample(NULL),
_decodeThread(NULL),
@@ -148,10 +147,6 @@
m_FormatCtx = NULL;
}
- if (m_Resample) {
- audio_resample_close (m_Resample);
- }
-
if (m_imageframe) delete m_imageframe;
while (m_qvideo.size() > 0)
@@ -576,6 +571,30 @@
ns->m_pause = false;
}
+
+/// Copy RGB data from a source raw_videodata_t to a destination image::rgb.
+/// @param dst the destination image::rgb, which must already be initialized
+/// with a buffer of size of at least src.m_size.
+/// @param src the source raw_videodata_t to copy data from. The m_size member
+/// of this structure must be initialized.
+/// @param width the width, in bytes, of a row of video data.
+static void
+rgbcopy(image::rgb* dst, raw_videodata_t* src, int width)
+{
+ assert(src->m_size <= dst->m_width * dst->m_height * 3);
+
+ uint8_t* dstptr = dst->m_data;
+
+ uint8_t* srcptr = src->m_data;
+ uint8_t* srcend = src->m_data + src->m_size;
+
+ while (srcptr < srcend) {
+ memcpy(dstptr, srcptr, width);
+ dstptr += dst->m_pitch;
+ srcptr += width;
+ }
+}
+
// decoder thread
void NetStreamFfmpeg::av_streamer(NetStreamFfmpeg* ns)
{
@@ -632,9 +651,12 @@
boost::mutex::scoped_lock lock(ns->image_mutex);
int videoFrameFormat =
gnash::render::videoFrameFormat();
if (videoFrameFormat == render::YUV) {
+ // XXX m_imageframe might be a byte
aligned buffer, while video is not!
static_cast<image::yuv*>(ns->m_imageframe)->update(video->m_data);
} else if (videoFrameFormat == render::RGB) {
- ns->m_imageframe->update(video->m_data);
+
+ image::rgb* imgframe =
static_cast<image::rgb*>(ns->m_imageframe);
+ rgbcopy(imgframe, video,
ns->m_VCodecCtx->width * 3);
}
ns->m_qvideo.pop();
delete video;
@@ -755,9 +777,11 @@
if (packet.stream_index == m_audio_index && get_sound_handler())
{
int frame_size;
- uint8_t* ptr = new
uint8_t[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
+ unsigned int bufsize = (AVCODEC_MAX_AUDIO_FRAME_SIZE *
3) / 2;
+
+ uint8_t* ptr = new uint8_t[bufsize];
#ifdef FFMPEG_AUDIO2
- frame_size = (AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2;
+ frame_size = bufsize;
if (avcodec_decode_audio2(m_ACodecCtx, (int16_t*) ptr,
&frame_size, packet.data, packet.size) >= 0)
#else
if (avcodec_decode_audio(m_ACodecCtx, (int16_t*) ptr,
&frame_size, packet.data, packet.size) >= 0)
@@ -767,24 +791,27 @@
bool stereo = m_ACodecCtx->channels > 1 ? true
: false;
int samples = stereo ? frame_size >> 2 :
frame_size >> 1;
- // Resampeling using ffmpegs (libavcodecs)
resampler
- if (!m_Resample) {
- // arguments: (output channels, input
channels, output rate, input rate)
- m_Resample = audio_resample_init (2,
m_ACodecCtx->channels, 44100, m_ACodecCtx->sample_rate);
- }
- // The size of this is a guess, we don't know
yet... Lets hope it's big enough
- int16_t* output_data = new int16_t[frame_size *
2];
- samples = audio_resample (m_Resample,
output_data, (int16_t*)ptr, samples);
+ if (_resampler.init(m_ACodecCtx)){
+ // Resampling is needed.
+
+ uint8_t* output = new uint8_t[bufsize];
+
+ samples =
_resampler.resample(reinterpret_cast<int16_t*>(ptr),
+
reinterpret_cast<int16_t*>(output),
+
samples);
+ delete [] ptr;
+ ptr =
reinterpret_cast<uint8_t*>(output);
+ }
raw_videodata_t* raw = new raw_videodata_t;
- raw->m_data = (uint8_t*) output_data;
+
+ raw->m_data = ptr;
raw->m_ptr = raw->m_data;
raw->m_size = samples * 2 * 2; // 2 for stereo
and 2 for samplesize = 2 bytes
raw->m_stream_index = m_audio_index;
m_unqueued_data = m_qaudio.push(raw) ? NULL :
raw;
}
- delete[] ptr;
}
else
if (packet.stream_index == m_video_index)
@@ -881,13 +908,21 @@
}
video->m_size = copied;
} else if (videoFrameFormat == render::RGB) {
- for(int line = 0; line <
m_VCodecCtx->height; line++)
- {
- for(int byte = 0; byte <
(m_VCodecCtx->width*3); byte++)
- {
- video->m_data[byte +
(line*m_VCodecCtx->width*3)] = (unsigned char)
*(m_Frame->data[0]+(line*m_Frame->linesize[0])+byte);
- }
+
+ uint8_t* srcptr = m_Frame->data[0];
+ uint8_t* srcend = m_Frame->data[0] +
m_Frame->linesize[0] * m_VCodecCtx->height;
+ uint8_t* dstptr = video->m_data;
+ unsigned int srcwidth =
m_VCodecCtx->width * 3;
+
+ video->m_size = 0;
+
+ while (srcptr < srcend) {
+ memcpy(dstptr, srcptr,
srcwidth);
+ srcptr += m_Frame->linesize[0];
+ dstptr += srcwidth;
+ video->m_size += srcwidth;
}
+
}
m_unqueued_data = m_qvideo.push(video) ? NULL :
video;
Index: server/asobj/NetStreamFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- server/asobj/NetStreamFfmpeg.h 8 Apr 2007 15:23:43 -0000 1.19
+++ server/asobj/NetStreamFfmpeg.h 10 Apr 2007 20:24:23 -0000 1.20
@@ -14,7 +14,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-/* $Id: NetStreamFfmpeg.h,v 1.19 2007/04/08 15:23:43 bjacques Exp $ */
+/* $Id: NetStreamFfmpeg.h,v 1.20 2007/04/10 20:24:23 bjacques Exp $ */
#ifndef __NETSTREAMFFMPEG_H__
#define __NETSTREAMFFMPEG_H__
@@ -138,6 +138,38 @@
std::queue < T > m_queue;
};
+
+class AudioResampler
+{
+public:
+ AudioResampler() : _context(NULL) {}
+ ~AudioResampler()
+ {
+ if(_context) {
+ audio_resample_close (_context);
+ }
+ }
+
+ bool init(AVCodecContext* ctx)
+ {
+ if (!_context && (ctx->sample_rate != 44100 && ctx->channels !=
2)) {
+ _context = audio_resample_init(2, ctx->channels,
+ 44100, ctx->sample_rate);
+ return true;
+ }
+ return false;
+ }
+
+ int resample(int16_t* input, int16_t* output, int samples)
+ {
+ return audio_resample (_context, output, input, samples);
+ }
+
+
+private:
+ ReSampleContext* _context;
+};
+
class NetStreamFfmpeg: public NetStream {
public:
NetStreamFfmpeg();
@@ -205,7 +237,7 @@
AVFrame* m_Frame;
// Use for resampling audio
- ReSampleContext *m_Resample;
+ AudioResampler _resampler;
boost::thread* _decodeThread;
boost::mutex decoding_mutex;
Index: libbase/image.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/image.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- libbase/image.cpp 5 Dec 2006 14:26:09 -0000 1.17
+++ libbase/image.cpp 10 Apr 2007 20:24:23 -0000 1.18
@@ -29,6 +29,13 @@
{
}
+ /// Copy image data from a buffer.
+ //
+ /// Note that this buffer MUST have the same m_pitch, or unexpected
things
+ /// will happen. In general, it is only safe to copy from another
image_base
+ /// (or derivative thereof) or unexpected things will happen.
+ ///
+ /// @param data buffer to copy data from.
void image_base::update(uint8_t* data)
{
memcpy(m_data, data, m_pitch * m_height);