* Fixes and updates on wxMMedia.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1999-02-18 18:18:06 +00:00
parent b2cce0c457
commit 8a7c9dcc1c
12 changed files with 84 additions and 27 deletions

View File

@@ -5,6 +5,7 @@
// Created: 1997 // Created: 1997
// Updated: 1998 // Updated: 1998
// Copyright: (C) 1997, 1998, Guilhem Lavaux // Copyright: (C) 1997, 1998, Guilhem Lavaux
// CVS Id: $Id$
// License: wxWindows license // License: wxWindows license
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__

View File

@@ -23,6 +23,7 @@
#include "sndau.h" #include "sndau.h"
#include "sndpcm.h" #include "sndpcm.h"
#include "sndmulaw.h" #include "sndmulaw.h"
#include "sndadpcm.h"
#include "vidbase.h" #include "vidbase.h"
#if defined(__X__) || defined(__WXGTK__) #if defined(__X__) || defined(__WXGTK__)
#include "vidxanm.h" #include "vidxanm.h"
@@ -50,6 +51,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSndSimpleBuffer, wxSndBuffer)
IMPLEMENT_ABSTRACT_CLASS(wxSoundCodec, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxSoundCodec, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxSoundPcmCodec, wxSoundCodec) IMPLEMENT_DYNAMIC_CLASS(wxSoundPcmCodec, wxSoundCodec)
IMPLEMENT_DYNAMIC_CLASS(wxSoundMulawCodec, wxSoundCodec) IMPLEMENT_DYNAMIC_CLASS(wxSoundMulawCodec, wxSoundCodec)
IMPLEMENT_DYNAMIC_CLASS(wxSoundAdpcmCodec, wxSoundCodec)
#ifdef __UNIX__ #ifdef __UNIX__
IMPLEMENT_DYNAMIC_CLASS(wxUssSound, wxSound) IMPLEMENT_DYNAMIC_CLASS(wxUssSound, wxSound)
@@ -66,7 +68,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSndAiffCodec, wxSndFileCodec)
IMPLEMENT_ABSTRACT_CLASS(wxVideoBaseDriver, wxMMediaFile) IMPLEMENT_ABSTRACT_CLASS(wxVideoBaseDriver, wxMMediaFile)
IMPLEMENT_DYNAMIC_CLASS(wxVideoOutput, wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxVideoOutput, wxWindow)
#if defined(__X__) || defined(__WXGTK__) #if defined(__X__) || defined(__WXGTK__)
// IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver) IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
#endif #endif
#ifdef __WINDOWS__ #ifdef __WINDOWS__
IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver) IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
@@ -88,7 +90,7 @@ MMD_REGISTER_FILE("audio/x-wav", "Wav Player", wxSndWavCodec, "wav")
MMD_REGISTER_FILE("audio/x-aiff", "Aiff Player", wxSndAiffCodec, "aif") MMD_REGISTER_FILE("audio/x-aiff", "Aiff Player", wxSndAiffCodec, "aif")
MMD_REGISTER_FILE("audio/x-au", "Sun Audio File Player", wxSndAuCodec, "au") MMD_REGISTER_FILE("audio/x-au", "Sun Audio File Player", wxSndAuCodec, "au")
#if defined(__X__) || defined(__WXGTK__) #if defined(__X__) || defined(__WXGTK__)
// MMD_REGISTER_FILE("video/*", "Video Player", wxVideoXANIM, "mov") MMD_REGISTER_FILE("video/*", "Video Player", wxVideoXANIM, "mov")
#else #else
MMD_REGISTER_FILE("video/avi", "AVI Player", wxVideoWindows, "avi") MMD_REGISTER_FILE("video/avi", "AVI Player", wxVideoWindows, "avi")
#endif #endif

View File

@@ -10,30 +10,65 @@
wxSoundAdpcmCodec::wxSoundAdpcmCodec() wxSoundAdpcmCodec::wxSoundAdpcmCodec()
: wxSoundCodec() : wxSoundCodec()
{ {
g72x_init_state(codec_state); // TODO: For the moment, only 1 channel is supported.
m_codec_state = new g72x_state;
g72x_init_state(m_codec_state);
} }
wxSoundAdpcmCodec::~wxSoundAdpcmCodec() wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
{ {
} }
void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
{
m_srate = format.GetSampleRate();
}
int wxSoundAdpcmCodec::GetBits(int nbits) int wxSoundAdpcmCodec::GetBits(int nbits)
{ {
unsigned int mask; unsigned int mask;
int bits; int bits;
if (bits_waiting == 0) if (m_bits_waiting == 0)
current_byte = m_in_sound->GetChar(); m_current_byte = m_in_sound->GetChar();
mask = (1 << nbits) - 1; mask = (1 << nbits) - 1;
bits = current_byte & mask; bits = m_current_byte & mask;
current_byte >>= nbits; m_current_byte >>= nbits;
m_bits_waiting -= nbits;
return bits; return bits;
} }
void wxSoundAdpcmCodec::Decode() void wxSoundAdpcmCodec::Decode()
{ {
int smp, bits;
wxSoundDataFormat pref_frmt;
pref_frmt = GetPreferredFormat(0);
if (!(m_io_format == pref_frmt))
ChainCodecAfter(pref_frmt);
bits = GetBits(4);
if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
while (!StreamOk()) {
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
m_out_sound->PutChar(smp & 0x00ff);
m_out_sound->PutChar((smp & 0xff00) >> 8);
bits = GetBits(4);
}
} else {
while (!StreamOk()) {
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
m_out_sound->PutChar((smp & 0xff00) >> 8);
m_out_sound->PutChar(smp & 0x00ff);
bits = GetBits(4);
}
}
}
void wxSoundAdpcmCodec::Encode()
{
/*
int smp; int smp;
wxSoundDataFormat pref_frmt; wxSoundDataFormat pref_frmt;
@@ -57,18 +92,15 @@ void wxSoundAdpcmCodec::Decode()
bits = GetBits(4); bits = GetBits(4);
} }
} }
*/
} }
void wxSoundMulawCodec::Encode() size_t wxSoundAdpcmCodec::GetByteRate() const
{ {
return (m_io_format.GetSampleRate() * m_io_format.GetChannels()) / 2;
} }
size_t wxSoundMulawCodec::GetByteRate() const wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
{
return m_srate;
}
wxSoundDataFormat wxSoundMulawCodec::GetPreferredFormat(int WXUNUSED(no)) const
{ {
wxSoundDataFormat format; wxSoundDataFormat format;

View File

@@ -86,8 +86,6 @@ wxUint32 wxSndAiffCodec::PrepareToPlay()
char tmp_buf[5]; char tmp_buf[5];
wxString chunk_name; wxString chunk_name;
m_istream->SeekI(0, wxFromStart);
wxSndFileCodec::m_mmerror = wxMMFILE_INVALID; wxSndFileCodec::m_mmerror = wxMMFILE_INVALID;
READ_STRING(chunk_name, 4); READ_STRING(chunk_name, 4);
@@ -127,6 +125,8 @@ wxUint32 wxSndAiffCodec::PrepareToPlay()
wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR; wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
m_istream->SeekI(m_spos, wxFromStart); m_istream->SeekI(m_spos, wxFromStart);
wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
return m_slen; return m_slen;
} }

View File

@@ -60,8 +60,9 @@ void wxSndFileCodec::Play(wxSound& snd)
if (m_fstate != wxSFILE_STOPPED || IsSet(wxSND_BUFLOCKED)) if (m_fstate != wxSFILE_STOPPED || IsSet(wxSND_BUFLOCKED))
return; return;
if (!(m_fsize = PrepareToPlay())) if (m_fstate != wxSFILE_PREPARED_TO_PLAY)
return; if (!(m_fsize = PrepareToPlay()))
return;
m_fpos = 0; m_fpos = 0;
m_fstate = wxSFILE_PLAYING; m_fstate = wxSFILE_PLAYING;
@@ -193,7 +194,7 @@ wxMMtime wxSndFileCodec::GetPosition()
wxMMtime wxSndFileCodec::GetLength() wxMMtime wxSndFileCodec::GetLength()
{ {
if (m_sndtime.hours == -1 && m_istream) if (m_sndtime.hours == -1 && m_istream)
PrepareToPlay(); m_fsize = PrepareToPlay();
return m_sndtime; return m_sndtime;
} }
@@ -202,7 +203,6 @@ bool wxSndFileCodec::TranslateBuffer(wxSndBuffer& buf)
{ {
#define TMP_BUFSIZE 10240 #define TMP_BUFSIZE 10240
wxUint32 buf_size;
wxStreamBuffer *tmp_buf; wxStreamBuffer *tmp_buf;
wxSoundCodec *codec_in, *codec_out; wxSoundCodec *codec_in, *codec_out;
wxSoundDataFormat std_format; wxSoundDataFormat std_format;

View File

@@ -27,7 +27,9 @@ public:
typedef enum { typedef enum {
wxSFILE_STOPPED, wxSFILE_STOPPED,
wxSFILE_PLAYING, wxSFILE_PLAYING,
wxSFILE_RECORDING wxSFILE_RECORDING,
wxSFILE_PREPARED_TO_PLAY,
wxSFILE_PREPARED_TO_RECORD,
} FileState; } FileState;
protected: protected:

View File

@@ -81,8 +81,10 @@ bool wxFragmentBuffer::NotifyOutputBuffer(wxSndBuffer *buf)
if (ptr == NULL) if (ptr == NULL)
return FALSE; return FALSE;
// Normally, these three functions could be called only once.
codec->SetOutStream(ptr->sndbuf); codec->SetOutStream(ptr->sndbuf);
codec->InitIO(m_drvformat); codec->InitIO(m_drvformat);
codec->InitMode(wxSoundCodec::DECODING);
// Fill it up // Fill it up
codec->Decode(); codec->Decode();
@@ -190,8 +192,10 @@ void wxFragmentBuffer::ClearBuffer(wxFragBufPtr *ptr)
} else { } else {
codec = buf->GetCurrentCodec(); codec = buf->GetCurrentCodec();
// Normally, these three functions could be called only once.
codec->SetInStream(ptr->sndbuf); codec->SetInStream(ptr->sndbuf);
codec->InitIO(m_drvformat); codec->InitIO(m_drvformat);
codec->InitMode(wxSoundCodec::ENCODING);
// As there is an "auto-stopper" in the codec, we don't worry ... // As there is an "auto-stopper" in the codec, we don't worry ...
codec->Encode(); codec->Encode();
@@ -248,10 +252,18 @@ void wxFragmentBuffer::OnBufferFinished(wxFragBufPtr *ptr)
buf->Clear(wxSND_BUFSTOP); buf->Clear(wxSND_BUFSTOP);
continue; continue;
} }
if (buf->GetMode() == wxSND_OUTPUT) switch (buf->GetMode()) {
case wxSND_OUTPUT:
ret = NotifyOutputBuffer(buf); ret = NotifyOutputBuffer(buf);
else break;
case wxSND_INPUT:
ret = NotifyInputBuffer(buf); ret = NotifyInputBuffer(buf);
break;
case wxSND_DUPLEX:
case wxSND_OTHER_IO:
// ret = NotifyDuplexBuffer(buf);
break;
}
buf->HardUnlock(); buf->HardUnlock();
} }

View File

@@ -114,6 +114,7 @@ void wxSoundDataFormat::CodecChange()
break; break;
} }
default: default:
codec->InitWith(*this);
break; break;
} }
} }
@@ -150,19 +151,19 @@ bool wxSoundDataFormat::operator ==(const wxSoundDataFormat& format) const
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include "sndpcm.h" #include "sndpcm.h"
//#include "sndadpcm.h" #include "sndadpcm.h"
//#include "sndalaw.h" //#include "sndalaw.h"
#include "sndmulaw.h" #include "sndmulaw.h"
static wxClassInfo *l_sound_formats[] = { static wxClassInfo *l_sound_formats[] = {
NULL, NULL,
CLASSINFO(wxSoundPcmCodec), CLASSINFO(wxSoundPcmCodec),
NULL, // CLASSINFO(wxSoundAdpcmCodec), CLASSINFO(wxSoundAdpcmCodec),
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, // CLASSINFO(wxSoundAlawCodec), NULL, // CLASSINFO(wxSoundAlawCodec),
NULL // CLASSINFO(wxSoundMulawCodec) CLASSINFO(wxSoundMulawCodec)
}; };
static int l_nb_formats = WXSIZEOF(l_sound_formats); static int l_nb_formats = WXSIZEOF(l_sound_formats);

View File

@@ -85,6 +85,7 @@ class wxSoundCodec : public wxObject, public wxStreamBase {
size_t Available(); size_t Available();
void InitIO(const wxSoundDataFormat& format); void InitIO(const wxSoundDataFormat& format);
virtual void InitWith(const wxSoundDataFormat& format) {}
inline void SetInStream(wxStreamBuffer *s) inline void SetInStream(wxStreamBuffer *s)
{ m_in_sound = s; } { m_in_sound = s; }

View File

@@ -162,6 +162,9 @@ bool wxUssSound::InitBuffer(wxSndBuffer *buf)
codec->InitIO(m_ussformat); codec->InitIO(m_ussformat);
codec->InitMode(wxSoundCodec::DECODING); codec->InitMode(wxSoundCodec::DECODING);
break; break;
case wxSND_DUPLEX:
case wxSND_OTHER_IO:
break;
} }
return TRUE; return TRUE;
} }
@@ -202,6 +205,7 @@ void *wxUssSound::Entry()
} }
buf->HardUnlock(); buf->HardUnlock();
continue; continue;
sound_clean_buffer: sound_clean_buffer:
buf->GetCurrentCodec()->ExitMode(); buf->GetCurrentCodec()->ExitMode();
delete node; delete node;

View File

@@ -106,6 +106,7 @@ wxUint32 wxSndWavCodec::PrepareToPlay()
m_sndtime.seconds = sec2 % 60; m_sndtime.seconds = sec2 % 60;
wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR; wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
return riff_codec.GetChunkLength(); return riff_codec.GetChunkLength();
} }

View File

@@ -25,6 +25,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Intrinsic.h> #include <X11/Intrinsic.h>
#ifdef __WXGTK__ #ifdef __WXGTK__
#include <gtk/gtkwidget.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gdk/gdkprivate.h> #include <gdk/gdkprivate.h>
#endif #endif