⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 av_stream_control.c

📁 针对bluelab3.42的handsfree车载蓝牙的参考
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.4.2-release

FILE NAME
    av_stream_control.c

DESCRIPTION
    Handles the actual AV streaming on Kalimba.

*/


/****************************************************************************
    Header files
*/
#include "headset_private.h"
#include "av_stream_control.h"
#include "cvc_headset.h"
#include "headset_common.h"
#include "headset_power.h"
#include "headset_tones.h"
#include "headset_volume.h"

#include <codec.h>
#include <file.h>
#include <kalimba.h>
#include <kalimba_standard_messages.h>
#include <panic.h>
#include <pcm.h>
#include <stdlib.h>
#include <string.h>
#include <transform.h>


#ifdef DEBUG_AVSTREAM
#define AVSTREAM_DEBUG(x) DEBUG(x)
#else
#define AVSTREAM_DEBUG(x) 
#endif


/**************************************************************************/
void configureCodec(headsetTaskData *app)
{
   uint32 sampleRate = app->rate;
   
   AVSTREAM_DEBUG(("AV: Configure Codec\n"));
   
#ifdef WOLFSON_CODEC
   if (app->rate == 44100)
       sampleRate = 44118;
#endif
   
   /* Disconnect anything already connected to PCM slots 0 and 1 */
    StreamDisconnect(StreamPcmSource(0), StreamPcmSink(0));
    StreamDisconnect(StreamPcmSource(1), StreamPcmSink(1));
   
   /*
      Set both ports to none to allow reassigning of internal DACs below.
      (A DAC can only be routed to one port at a time!)
   */
   (void) PanicFalse(PcmClearRouting(0));
   (void) PanicFalse(PcmClearRouting(1));

   /* Is it mono playback? */
   if (app->channel_mode == a2dp_mono)
   {
       /* Mono - Set both DACs to play the output of port 0. */
#ifdef WOLFSON_CODEC
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
#else
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, (uint32) 8000, VM_PCM_INTERNAL_A_AND_B));
#endif
   }
   else
   {
      /*
         Stereo - Configure port 0 and 1 to be left and right channels
         and synchronise buffer offsets for stereo playback.
      */
#ifdef WOLFSON_CODEC
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
      (void) PanicFalse(PcmRateAndRoute(1, 0, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));

       CodecConfigure(app->codec_task,0);
#else
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, (uint32) 8000, VM_PCM_INTERNAL_A));
      (void) PanicFalse(PcmRateAndRoute(1, 0, sampleRate, (uint32) 8000, VM_PCM_INTERNAL_B));
#endif
   }
}


/**************************************************************************/
void avHeadsetConnectKalimbaToPcm(a2dp_channel_mode chn_mode)
{
    /* is it mono playback? */
    if (chn_mode == a2dp_mono)
    {
        AVSTREAM_DEBUG(("AV: Mono\n"));
        /* plug port 0 into both DACs */
        (void) PanicFalse(StreamConnect(StreamKalimbaSource(0),StreamPcmSink(0)));
    }
    else
    {
        AVSTREAM_DEBUG(("AV: Stereo\n"));
        /* plug port 0 into Left DAC */
        (void) PanicFalse(StreamConnect(StreamKalimbaSource(0),StreamPcmSink(0)));

        /* plug port 1 into Right DAC */
        (void) PanicFalse(StreamConnect(StreamKalimbaSource(1),StreamPcmSink(1)));
    }
}


/**************************************************************************/
void avHeadsetStartKalimba(headsetTaskData* app)
{
    AVSTREAM_DEBUG(("AV: Start Kalimba\n"));
    
    /* Start decode */
    A2dpAudioCodecEnable(app->a2dp, app->media_sink);
   
    avHeadsetConnectKalimbaToPcm(app->channel_mode);    

    /* Start decode */
    if(!KalimbaSendMessage(KALIMBA_MSG_GO,0,0,0,0))
    {
        AVSTREAM_DEBUG(("AV: Message KALIMBA_MSG_GO failed!\n"));
        Panic();
    }
        

/*    app->led_state |= LED_STREAMING; removed by HJB*/
	app->led_state |= LED_CONNECTED;
    app->active_profile = av_active;
    app->av_stream_stopped = FALSE;
}


/**************************************************************************/
void avHeadsetAvStreamStop(headsetTaskData* app, bool send_suspend)
{
    if (app->av_stream_stopped || !app->media_sink)
        return;

    AVSTREAM_DEBUG(("AV: Stream Stop...\n"));

    /* Stop decode */
    A2dpAudioCodecDisable(app->a2dp, app->media_sink);

    if (send_suspend)
        A2dpSuspend(app->a2dp, app->media_sink);

 /*   app->led_state &= ~LED_STREAMING;  removed by HJB*/
    app->av_stream_stopped = TRUE;
    
    /* Start the timer to shut down the audio amp */
    MessageSendLater(getAppTask(), APP_AMP_IDLE_IND, 0, AMP_IDLE_TIMER);
}


/**************************************************************************/
void avHeadsetAvStreamStart(headsetTaskData* app)
{
    if (!app->av_stream_stopped || !app->media_sink)
        return;

    AVSTREAM_DEBUG(("AV: Stream Start...\n"));
    
    if (isTonePlaying(app->pcm_audio_state))
    {
        setPcmState(app, pcm_tone_to_av);
        AVSTREAM_DEBUG(("AV: Tone playing\n"));
        return;
    }
    else
    {
        setPcmState(app, pcm_av);
    }
    
    /* Set the local volume to mute */
    headsetUpdateVolume(app->codec_task, 0);
    
#ifdef INCLUDE_CVC
    if (app->cvc.hfkdspready)
    {
        CvcHeadsetUnloaded(app);
        KalimbaPowerOff();
    }
#endif
   
    /* Make sure amp is powered on */
    headsetPowerAmp(app, TRUE);

    /* Cancel the timer to shut down the audio amp */
    MessageCancelAll(getAppTask(), APP_AMP_IDLE_IND);

    /* Configure the DACs for the codec configuration */
    configureCodec(app);

    if (app->sent_suspend)
    {
        A2dpStart(app->a2dp, app->media_sink);
        app->sent_suspend = FALSE;
    }
    else
        avHeadsetStartKalimba(app);
    
    /* Set the local volume back to what it was */
    headsetUpdateVolume(app->codec_task, app->speaker_volume.av_volume);

    /* app->led_state |= LED_STREAMING; */
	app->led_state |= LED_CONNECTED;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -