content/media/omx/AudioSink.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/omx/AudioSink.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/*
     1.7 + * Copyright (c) 2014 The Linux Foundation. All rights reserved.
     1.8 + * Copyright (C) 2007 The Android Open Source Project
     1.9 + *
    1.10 + * Licensed under the Apache License, Version 2.0 (the "License");
    1.11 + * you may not use this file except in compliance with the License.
    1.12 + * You may obtain a copy of the License at
    1.13 + *
    1.14 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing, software
    1.17 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.19 + * See the License for the specific language governing permissions and
    1.20 + * limitations under the License.
    1.21 + */
    1.22 +
    1.23 +#ifndef AUDIO_SINK_H_
    1.24 +#define AUDIO_SINK_H_
    1.25 +
    1.26 +#include <utils/Errors.h>
    1.27 +#include <utils/String8.h>
    1.28 +#include <system/audio.h>
    1.29 +
    1.30 +#define DEFAULT_AUDIOSINK_BUFFERCOUNT 4
    1.31 +#define DEFAULT_AUDIOSINK_BUFFERSIZE 1200
    1.32 +#define DEFAULT_AUDIOSINK_SAMPLERATE 44100
    1.33 +
    1.34 +// when the channel mask isn't known, use the channel count to derive a mask in
    1.35 +// AudioSink::open()
    1.36 +#define CHANNEL_MASK_USE_CHANNEL_ORDER 0
    1.37 +
    1.38 +namespace mozilla {
    1.39 +
    1.40 +/**
    1.41 + * AudioSink: abstraction layer for audio output
    1.42 + * Stripped version of Android KK MediaPlayerBase::AudioSink class
    1.43 + */
    1.44 +
    1.45 +class AudioSink : public android::RefBase
    1.46 +{
    1.47 +  typedef android::String8 String8;
    1.48 +  typedef android::status_t status_t;
    1.49 +
    1.50 +public:
    1.51 +  enum cb_event_t {
    1.52 +    CB_EVENT_FILL_BUFFER,   // Request to write more data to buffer.
    1.53 +    CB_EVENT_STREAM_END,    // Sent after all the buffers queued in AF and HW
    1.54 +                            // are played back (after stop is called)
    1.55 +    CB_EVENT_TEAR_DOWN      // The AudioTrack was invalidated due to usecase
    1.56 +                            // change. Need to re-evaluate offloading options
    1.57 +  };
    1.58 +
    1.59 +  // Callback returns the number of bytes actually written to the buffer.
    1.60 +  typedef size_t (*AudioCallback)(AudioSink* aAudioSink,
    1.61 +                                  void* aBuffer,
    1.62 +                                  size_t aSize,
    1.63 +                                  void* aCookie,
    1.64 +                                  cb_event_t aEvent);
    1.65 +  virtual ~AudioSink() {}
    1.66 +  virtual ssize_t FrameSize() const = 0;
    1.67 +  virtual status_t GetPosition(uint32_t* aPosition) const = 0;
    1.68 +  virtual status_t SetVolume(float aVolume) const = 0;
    1.69 +  virtual status_t SetParameters(const String8& aKeyValuePairs)
    1.70 +  {
    1.71 +    return android::NO_ERROR;
    1.72 +  }
    1.73 +
    1.74 +  virtual status_t Open(uint32_t aSampleRate,
    1.75 +                        int aChannelCount,
    1.76 +                        audio_channel_mask_t aChannelMask,
    1.77 +                        audio_format_t aFormat=AUDIO_FORMAT_PCM_16_BIT,
    1.78 +                        AudioCallback aCb = nullptr,
    1.79 +                        void* aCookie = nullptr,
    1.80 +                        audio_output_flags_t aFlags = AUDIO_OUTPUT_FLAG_NONE,
    1.81 +                        const audio_offload_info_t* aOffloadInfo = nullptr) = 0;
    1.82 +
    1.83 +  virtual status_t Start() = 0;
    1.84 +  virtual void Stop() = 0;
    1.85 +  virtual void Flush() = 0;
    1.86 +  virtual void Pause() = 0;
    1.87 +  virtual void Close() = 0;
    1.88 +};
    1.89 +
    1.90 +} // namespace mozilla
    1.91 +
    1.92 +#endif // AUDIO_SINK_H_

mercurial