• Interface
  • Building a Camera Library
  • Sequence Diagrams
  • Taking a Picture
  • Building an Audio Library




    Download 1.03 Mb.
    bet8/10
    Sana22.12.2019
    Hajmi1.03 Mb.
    1   2   3   4   5   6   7   8   9   10

    Building an Audio Library


    To implement an audio driver, create a shared library that implements the interface defined in AudioHardwareInterface.h. You must name your shared library libaudio.so so that it will get loaded from /system/lib at runtime. Place libaudio sources and Android.mk in vendor/acme/chipset_or_board/libaudio/.

    The following stub Android.mk file ensures that libaudio compiles and links to the appropriate libraries:

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)


    LOCAL_MODULE := libaudio
    LOCAL_SHARED_LIBRARIES := \

    libcutils \

    libutils \

    libmedia \

    libhardware
    LOCAL_SRC_FILES += MyAudioHardware.cpp
    LOCAL_CFLAGS +=
    LOCAL_C_INCLUDES +=
    LOCAL_STATIC_LIBRARIES += libaudiointerface
    include $(BUILD_SHARED_LIBRARY)

    Interface


    Note: This document relies on some Doxygen-generated content that appears in an iFrame below. To return to the Doxygen default content for this page, click here.

    AudioHardwareInterface.h

    Go to the documentation of this file.

    00001 /*


    00002 * Copyright (C) 2007 The Android Open Source Project

    00003 *


    00004 * Licensed under the Apache License, Version 2.0 (the "License");

    00005 * you may not use this file except in compliance with the License.

    00006 * You may obtain a copy of the License at

    00007 *


    00008 * http://www.apache.org/licenses/LICENSE-2.0

    00009 *


    00010 * Unless required by applicable law or agreed to in writing, software

    00011 * distributed under the License is distributed on an "AS IS" BASIS,

    00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    00013 * See the License for the specific language governing permissions and

    00014 * limitations under the License.

    00015 */


    00016

    00017 #ifndef ANDROID_AUDIO_HARDWARE_INTERFACE_H

    00018 #define ANDROID_AUDIO_HARDWARE_INTERFACE_H

    00019


    00020 #include

    00021 #include

    00022

    00023 #include



    00024 #include

    00025 #include

    00026

    00027 #include



    00028 #include "media/AudioSystem.h"

    00029


    00030

    00031 namespace android {

    00032


    00033 // ----------------------------------------------------------------------------

    00034


    00035 /**

    00036 * AudioStreamOut is the abstraction interface for the audio output hardware.

    00037 *

    00038 * It provides information about various properties of the audio output hardware driver.



    00039 */

    00040 class AudioStreamOut {

    00041 public:

    00042 virtual ~AudioStreamOut() = 0;

    00043


    00044 /** return audio sampling rate in hz - eg. 44100 */

    00045 virtual uint32_t sampleRate() const = 0;

    00046

    00047 /** returns size of output buffer - eg. 4800 */



    00048 virtual size_t bufferSize() const = 0;

    00049


    00050 /**

    00051 * return number of output audio channels.

    00052 * Acceptable values are 1 (mono) or 2 (stereo)

    00053 */


    00054 virtual int channelCount() const = 0;

    00055


    00056 /**

    00057 * return audio format in 8bit or 16bit PCM format -

    00058 * eg. AudioSystem:PCM_16_BIT

    00059 */


    00060 virtual int format() const = 0;

    00061


    00062 /**

    00063 * return the frame size (number of bytes per sample).

    00064 */

    00065 uint32_t frameSize() const { return channelCount()*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); }

    00066


    00067 /**

    00068 * return the audio hardware driver latency in milli seconds.

    00069 */

    00070 virtual uint32_t latency() const = 0;

    00071

    00072 /**



    00073 * Use this method in situations where audio mixing is done in the

    00074 * hardware. This method serves as a direct interface with hardware,

    00075 * allowing you to directly set the volume as apposed to via the framework.

    00076 * This method might produce multiple PCM outputs or hardware accelerated

    00077 * codecs, such as MP3 or AAC.

    00078 */


    00079 virtual status_t setVolume(float volume) = 0;

    00080


    00081 /** write audio buffer to driver. Returns number of bytes written */

    00082 virtual ssize_t write(const void* buffer, size_t bytes) = 0;

    00083

    00084 /**



    00085 * Put the audio hardware output into standby mode. Returns

    00086 * status based on include/utils/Errors.h

    00087 */

    00088 virtual status_t standby() = 0;

    00089

    00090 /** dump the state of the audio output device */



    00091 virtual status_t dump(int fd, const Vector& args) = 0;

    00092 };


    00093

    00094 /**

    00095 * AudioStreamIn is the abstraction interface for the audio input hardware.

    00096 *


    00097 * It defines the various properties of the audio hardware input driver.

    00098 */


    00099 class AudioStreamIn {

    00100 public:

    00101 virtual ~AudioStreamIn() = 0;

    00102


    00103 /** return the input buffer size allowed by audio driver */

    00104 virtual size_t bufferSize() const = 0;

    00105

    00106 /** return the number of audio input channels */



    00107 virtual int channelCount() const = 0;

    00108


    00109 /**

    00110 * return audio format in 8bit or 16bit PCM format -

    00111 * eg. AudioSystem:PCM_16_BIT

    00112 */


    00113 virtual int format() const = 0;

    00114


    00115 /**

    00116 * return the frame size (number of bytes per sample).

    00117 */

    00118 uint32_t frameSize() const { return channelCount()*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); }

    00119

    00120 /** set the input gain for the audio driver. This method is for



    00121 * for future use */

    00122 virtual status_t setGain(float gain) = 0;

    00123

    00124 /** read audio buffer in from audio driver */



    00125 virtual ssize_t read(void* buffer, ssize_t bytes) = 0;

    00126


    00127 /** dump the state of the audio input device */

    00128 virtual status_t dump(int fd, const Vector& args) = 0;

    00129

    00130 /**



    00131 * Put the audio hardware input into standby mode. Returns

    00132 * status based on include/utils/Errors.h

    00133 */

    00134 virtual status_t standby() = 0;

    00135

    00136 };



    00137

    00138 /**

    00139 * AudioHardwareInterface.h defines the interface to the audio hardware abstraction layer.

    00140 *


    00141 * The interface supports setting and getting parameters, selecting audio routing

    00142 * paths, and defining input and output streams.

    00143 *

    00144 * AudioFlinger initializes the audio hardware and immediately opens an output stream.

    00145 * You can set Audio routing to output to handset, speaker, Bluetooth, or a headset.

    00146 *


    00147 * The audio input stream is initialized when AudioFlinger is called to carry out

    00148 * a record operation.

    00149 */

    00150 class AudioHardwareInterface

    00151 {

    00152 public:

    00153 virtual ~AudioHardwareInterface() {}

    00154


    00155 /**

    00156 * check to see if the audio hardware interface has been initialized.

    00157 * return status based on values defined in include/utils/Errors.h

    00158 */

    00159 virtual status_t initCheck() = 0;

    00160


    00161 /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */

    00162 virtual status_t setVoiceVolume(float volume) = 0;

    00163

    00164 /**



    00165 * set the audio volume for all audio activities other than voice call.

    00166 * Range between 0.0 and 1.0. If any value other than NO_ERROR is returned,

    00167 * the software mixer will emulate this capability.

    00168 */

    00169 virtual status_t setMasterVolume(float volume) = 0;

    00170


    00171 /**

    00172 * Audio routing methods. Routes defined in include/hardware_legacy/AudioSystem.h.

    00173 * Audio routes can be (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH

    00174 * | ROUTE_HEADSET)

    00175 *

    00176 * setRouting sets the routes for a mode. This is called at startup. It is

    00177 * also called when a new device is connected, such as a wired headset is

    00178 * plugged in or a Bluetooth headset is paired.

    00179 */

    00180 virtual status_t setRouting(int mode, uint32_t routes) = 0;

    00181

    00182 virtual status_t getRouting(int mode, uint32_t* routes) = 0;



    00183

    00184 /**

    00185 * setMode is called when the audio mode changes. NORMAL mode is for

    00186 * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL

    00187 * when a call is in progress.

    00188 */

    00189 virtual status_t setMode(int mode) = 0;

    00190 virtual status_t getMode(int* mode) = 0;

    00191

    00192 // mic mute



    00193 virtual status_t setMicMute(bool state) = 0;

    00194 virtual status_t getMicMute(bool* state) = 0;

    00195

    00196 // Temporary interface, do not use



    00197 // TODO: Replace with a more generic key:value get/set mechanism

    00198 virtual status_t setParameter(const char* key, const char* value) = 0;

    00199

    00200 // Returns audio input buffer size according to parameters passed or 0 if one of the



    00201 // parameters is not supported

    00202 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0;

    00203

    00204 /** This method creates and opens the audio hardware output stream */



    00205 virtual AudioStreamOut* openOutputStream(

    00206 int format=0,

    00207 int channelCount=0,

    00208 uint32_t sampleRate=0,

    00209 status_t *status=0) = 0;

    00210


    00211 /** This method creates and opens the audio hardware input stream */

    00212 virtual AudioStreamIn* openInputStream(

    00213 int inputSource,

    00214 int format,

    00215 int channelCount,

    00216 uint32_t sampleRate,

    00217 status_t *status,

    00218 AudioSystem::audio_in_acoustics acoustics) = 0;

    00219

    00220 /**This method dumps the state of the audio hardware */



    00221 virtual status_t dumpState(int fd, const Vector& args) = 0;

    00222


    00223 static AudioHardwareInterface* create();

    00224


    00225 protected:

    00226 /**

    00227 * doRouting actually initiates the routing. A call to setRouting

    00228 * or setMode may result in a routing change. The generic logic calls

    00229 * doRouting when required. If the device has any special requirements these

    00230 * methods can be overriden.

    00231 */

    00232 virtual status_t doRouting() = 0;

    00233

    00234 virtual status_t dump(int fd, const Vector& args) = 0;



    00235 };

    00236


    00237 // ----------------------------------------------------------------------------

    00238


    00239 extern "C" AudioHardwareInterface* createAudioHardware(void);

    00240


    00241 }; // namespace android

    00242


    00243 #endif // ANDROID_AUDIO_HARDWARE_INTERFACE_H

    Camera

    In this document


    Android's camera subsystem connects the camera application to the application framework and user space libraries, which in turn communicate with the camera hardware layer that operates the physical camera.

    The diagram below illustrates the structure of the camera subsystem.





    Building a Camera Library


    To implement a camera driver, create a shared library that implements the interface defined in CameraHardwareInterface.h. You must name your shared library libcamera.so so that it will get loaded from /system/lib at runtime. Place libcamera sources and Android.mk in vendor/acme/chipset_or_board/libcamera/.

    The following stub Android.mk file ensures that libcamera compiles and links to the appropriate libraries:

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)


    LOCAL_MODULE := libcamera
    LOCAL_SHARED_LIBRARIES := \

    libutils \

    librpc \

    liblog
    LOCAL_SRC_FILES += MyCameraHardware.cpp


    LOCAL_CFLAGS +=
    LOCAL_C_INCLUDES +=
    LOCAL_STATIC_LIBRARIES += \

    libcamera-common \

    libclock-rpc \

    libcommondefs-rpc


    include $(BUILD_SHARED_LIBRARY)

    Sequence Diagrams

    Preview


    The following diagram illustrates the sequence of function calls and actions necessary for your camera to preview.




    Taking a Picture


    The following diagram illustrates the sequence of function calls and actions necessary for your camera to take a picture.



    CameraHardwareInterface.h File Reference

    Go to the source code of this file.








    Namespaces

    namespace  

    android


    Data Structures

    class  

    android::CameraHardwareInterface

     

    CameraHardwareInterface.h defines the interface to the camera hardware abstraction layer, used for setting and getting parameters, live previewing, and taking pictures. More...


    Typedefs

    typedef void(* 

    android::autofocus_callback )(bool focused, void *user)

     

    Callback for autoFocus().

    typedef void(* 

    android::jpeg_callback )(const sp< IMemory > &mem, void *user)

     

    Callback for takePicture().

    typedef void(* 

    android::preview_callback )(const sp< IMemory > &mem, void *user)

     

    Callback for startPreview().

    typedef void(* 

    android::raw_callback )(const sp< IMemory > &mem, void *user)

     

    Callback for takePicture().

    typedef void(* 

    android::recording_callback )(nsecs_t timestamp, const sp< IMemory > &mem, void *user)

     

    Callback for startRecord().

    typedef void(* 

    android::shutter_callback )(void *user)

     

    Callback for takePicture().


    Functions

    sp< CameraHardwareInterface > 

    android::openCameraHardware ()

     

    factory function to instantiate a camera hardware object


    Power Management

    Introduction
    Wake Locks

    Types of Wake Locks
    Exploring a Wake Lock Example

    PowerManager class
    Registering Drivers with the PM Driver
    Early Suspend

    Introduction

    Android supports its own Power Management (on top of the standard Linux Power Management) designed with the premise that the CPU shouldn't consume power if no applications or services require power. For more information regarding standard Linux power management, please see Linux Power Management Support at http://kernel.org.

    Android requires that applications and services request CPU resources with "wake locks" through the Android application framework and native Linux libraries. If there are no active wake locks, Android will shut down the CPU.



    The image below illustrates the Android power management architecture.

    Solid elements represent Android blocks and dashed elements represent partner-specific blocks.



    Download 1.03 Mb.
    1   2   3   4   5   6   7   8   9   10




    Download 1.03 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Building an Audio Library

    Download 1.03 Mb.