Commit e4eb1065 authored by Eric Petit's avatar Eric Petit

* src/modules/raw2ts/*, src/modules/v4lreader/*:

       started work on audio capturing and encoding.
       it is not fonctionnal yet (it captures and encodes to mp2, but
       there is something wrong in the encapsulation - and maybe somewhere
       else too ;) )
 * missing .cvsignores
parent b262b783
......@@ -2,7 +2,7 @@
* raw2ts.cpp: raw -> ES ffmpeg encoder -> TS
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: raw2ts.cpp,v 1.6 2003/01/29 03:27:19 tooney Exp $
* $Id: raw2ts.cpp,v 1.7 2003/02/20 05:57:23 titer Exp $
*
* Authors: Tristan Leteurtre <tooney@videolan.org>
* (inspirated from Fabrice Bellard...)
......@@ -102,6 +102,7 @@ void C_Raw2TsMpegConverter::InitWork()
C_MpegConverter::InitWork();
iVideoContinuityCounter = 0;
iAudioContinuityCounter = 0;
iPATContinuityCounter = 0;
iPMTContinuityCounter = 0;
......@@ -161,7 +162,7 @@ void C_Raw2TsMpegConverter::InitWork()
if (avcodec_open(m_CodecContext, m_Codec) < 0)
{
throw E_Exception(GEN_ERR, "Cannot init encoder");
throw E_Exception(GEN_ERR, "Cannot init video encoder");
}
/* Be carefull ! Some parameters may have changed, like palette ! */
......@@ -175,6 +176,29 @@ void C_Raw2TsMpegConverter::InitWork()
m_Picture = (AVPicture *)malloc(sizeof(AVPicture));
// sound
register_avcodec(&mp2_encoder);
m_AudioCodec = avcodec_find_encoder( CODEC_ID_MP2 );
if( !m_AudioCodec )
{
throw E_Exception(GEN_ERR, "Cannot find encoder MP2 Audio");
}
m_AudioCodecContext = avcodec_alloc_context();
m_AudioCodecContext->bit_rate = 64000;
m_AudioCodecContext->sample_rate = 44100;
m_AudioCodecContext->channels = 2;
if( avcodec_open( m_AudioCodecContext, m_AudioCodec ) < 0 )
{
throw E_Exception(GEN_ERR, "Cannot init audio encoder");
}
m_iAudioSampleBufSize = 2 * m_AudioCodecContext->frame_size *
m_AudioCodecContext->channels;
m_iAudioOutBufSize = 10000; // FIXME: totally arbitrary !
m_AudioSampleBuf = (byte*)malloc( m_iAudioSampleBufSize );
m_AudioOutBuf = (byte*)malloc( m_iAudioOutBufSize );
}
......@@ -255,8 +279,21 @@ void C_Raw2TsMpegConverter::DoWork()
PesPacket->BuildPacket(TimeStamp, 0xE0, m_OutBuf, m_iOutSize);
TSPacketization(PesPacket,TimeStamp, &iVideoContinuityCounter);
TSPacketization(PesPacket, TimeStamp, 0xE0, &iVideoContinuityCounter);
// Get and encode the sound
// FIXME: we currently encode a arbitraty size of data without
// thinking about his time length
m_pReader->GetAudioFrame(&m_AudioSampleBuf, m_iAudioSampleBufSize);
int outSize;
outSize = avcodec_encode_audio( m_AudioCodecContext, m_AudioOutBuf,
m_iAudioSampleBufSize, (short*)m_AudioSampleBuf );
PesPacket = new C_PesPacket();
PesPacket->BuildPacket(TimeStamp, 0xC0, m_AudioOutBuf, outSize );
TSPacketization(PesPacket, TimeStamp, 0xC0, &iAudioContinuityCounter);
if(iRc == MPEG_ENDOFSTREAM)
{
C_String strPgrmName = m_pBroadcast->GetProgram()->GetName();
......@@ -287,7 +324,8 @@ void C_Raw2TsMpegConverter::DoWork()
// Packetizer :
// - ADDs PES Header
// - packtizes in TS packets
void C_Raw2TsMpegConverter::TSPacketization(C_PesPacket * PesPacket, int TimeStamp, int * iCC)
void C_Raw2TsMpegConverter::TSPacketization(C_PesPacket * PesPacket,
int TimeStamp, u8 iPayloadType, int * iCC)
{
C_TsPacket * pPacket ;
unsigned int iTmpSize, iHeader;
......@@ -298,7 +336,7 @@ void C_Raw2TsMpegConverter::TSPacketization(C_PesPacket * PesPacket, int TimeSta
iTmpSize -= (TS_PACKET_LEN - iHeader))
{
pPacket = m_pTsProvider->GetPacket();
pPacket->BuildHeader(0xE0, bUnitStart, (*iCC)++);
pPacket->BuildHeader(iPayloadType, bUnitStart, (*iCC)++);
iHeader = 4;
if (bUnitStart)
......
......@@ -2,7 +2,7 @@
* raw2ts.h: raw -> ES ffmpeg encoder -> TS
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: raw2ts.h,v 1.3 2003/01/29 02:56:21 tooney Exp $
* $Id: raw2ts.h,v 1.4 2003/02/20 05:57:23 titer Exp $
*
* Authors: Tristan Leteurtre <tooney@videolan.org>
*
......@@ -48,24 +48,31 @@ protected:
virtual void InitWork();
virtual void DoWork();
void TSPacketization(C_PesPacket * PesPacket, int TimeStamp, int * iCC);
void TSPacketization(C_PesPacket * PesPacket, int TimeStamp,
u8 iPayloadType, int * iCC);
u64 GetTime();
// ffmpeg variables
AVCodec * m_Codec;
AVCodecContext *m_CodecContext;
AVCodec * m_AudioCodec;
AVCodecContext *m_AudioCodecContext;
// buffers
// AVFrame * m_Frame;
AVPicture * m_Picture;
byte *m_OutBuf, *m_PictureBuf;
int m_iOutBufSize, m_iOutSize, m_iPictureBufSize;
byte *m_AudioOutBuf, // to store encoded data
*m_AudioSampleBuf; // to store the raw data coming from dsp
int m_iAudioOutBufSize, m_iAudioSampleBufSize;
// parameters of the image
int m_iHeight, m_iWidth, m_iFrameRate, m_iPalette;
int iVideoContinuityCounter;
int iAudioContinuityCounter;
int iPATContinuityCounter, iPMTContinuityCounter ;
};
......
......@@ -2,7 +2,7 @@
* v4lreader.cpp: Reading from a v4l device (WebCam, tv tuner)
*-------------------------------------------------------------------------------
* (c)1999-2002 VideoLAN
* $Id: v4lreader.cpp,v 1.5 2003/01/29 02:24:46 tooney Exp $
* $Id: v4lreader.cpp,v 1.6 2003/02/20 05:57:23 titer Exp $
*
* Authors: Tristan Leteurtre <tooney@videolan.org>
*
......@@ -49,6 +49,7 @@
#include "v4lreader.h"
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
......@@ -334,6 +335,54 @@ void C_v4lMpegReader::Init()
m_pBroadcast->SetOption("Palette",PIX_FMT_YUV420P);
break;
}
/* sound stuff now */
/* open the device */
if( ( m_iAudioFD = open( "/dev/dsp", O_RDONLY ) ) < 0 )
{
fprintf( stderr, "could not open /dev/dsp for reading\n" );
return;
}
/* 16 bits samples, little endian */
int format = AFMT_S16_LE;
if( ioctl( m_iAudioFD, SNDCTL_DSP_SETFMT, &format ) < 0 )
{
fprintf( stderr, "ioctl SNDCTL_DSP_SETFMT failed\n" );
return;
}
if( format != AFMT_S16_LE )
{
fprintf( stderr, "AFMT_S16_LE not supported\n" );
return;
}
/* channel count */
int stereo = 1;
if( ioctl( m_iAudioFD, SNDCTL_DSP_STEREO, &stereo ) < 0 )
{
fprintf( stderr, "ioctl SNDCTL_DSP_STEREO failed\n" );
return;
}
if( stereo != 1 )
{
fprintf( stderr, "stereo not supported\n" );
return;
}
/* sample rate */
int sample_rate = 44100;
if( ioctl( m_iAudioFD, SNDCTL_DSP_SPEED, &sample_rate ) < 0 )
{
fprintf( stderr, "ioctl SNDCTL_DSP_SPEED failed\n" );
return;
}
if( sample_rate != sample_rate )
{
fprintf( stderr, "sample rate not supported\n" );
return;
}
}
......@@ -343,6 +392,7 @@ void C_v4lMpegReader::Init()
void C_v4lMpegReader::Close()
{
close(m_hFd);
close(m_iAudioFD);
}
......@@ -383,6 +433,11 @@ int C_v4lMpegReader::GetFrame(byte ** ppBuff , int iSize)
return 0;
}
int C_v4lMpegReader::GetAudioFrame(byte ** ppBuff, int iSize)
{
return( read( m_iAudioFD, *ppBuff, iSize ) );
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
......
......@@ -2,7 +2,7 @@
* v4lreader.h: eading from a v4l device (WebCam, tv tuner)
*-------------------------------------------------------------------------------
* (c)1999-2002 VideoLAN
* $Id: v4lreader.h,v 1.3 2003/01/17 19:34:17 tooney Exp $
* $Id: v4lreader.h,v 1.4 2003/02/20 05:57:23 titer Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Tristan Leteutre <tooney@videolan.org>
......@@ -57,7 +57,7 @@ public:
virtual s64 GetPos();
virtual int GetFrame(byte ** pBuff ,int iSize);
virtual int GetAudioFrame(byte ** pBuff ,int iSize);
protected:
......@@ -92,6 +92,9 @@ protected:
byte * m_pPictureBuffer; // Pointer to the picture buffer
// variables for dsp reading
int m_iAudioFD; // file descriptor
};
......
......@@ -2,7 +2,7 @@
* reader.h: Stream readers
*-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN
* $Id: reader.h,v 1.3 2002/12/11 23:02:23 tooney Exp $
* $Id: reader.h,v 1.4 2003/02/20 05:57:23 titer Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
*
......@@ -60,6 +60,7 @@ public:
virtual int Seek(s64 iOffset, int bStartPos) = 0;
virtual int GetFrame(byte ** pBuff ,int iSize) = 0;
int GetAudioFrame(byte ** pBuff ,int iSize) { return 0; } /* for V4L only */
virtual s64 Size() = 0;
virtual s64 GetPos() = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment