* 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
// Updated: 1998
// Copyright: (C) 1997, 1998, Guilhem Lavaux
// CVS Id: $Id$
// License: wxWindows license
////////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__

View File

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

View File

@@ -10,30 +10,65 @@
wxSoundAdpcmCodec::wxSoundAdpcmCodec()
: 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()
{
}
void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
{
m_srate = format.GetSampleRate();
}
int wxSoundAdpcmCodec::GetBits(int nbits)
{
unsigned int mask;
int bits;
if (bits_waiting == 0)
current_byte = m_in_sound->GetChar();
if (m_bits_waiting == 0)
m_current_byte = m_in_sound->GetChar();
mask = (1 << nbits) - 1;
bits = current_byte & mask;
current_byte >>= nbits;
bits = m_current_byte & mask;
m_current_byte >>= nbits;
m_bits_waiting -= nbits;
return bits;
}
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;
wxSoundDataFormat pref_frmt;
@@ -57,18 +92,15 @@ void wxSoundAdpcmCodec::Decode()
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
{
return m_srate;
}
wxSoundDataFormat wxSoundMulawCodec::GetPreferredFormat(int WXUNUSED(no)) const
wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
{
wxSoundDataFormat format;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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