summaryrefslogtreecommitdiff
path: root/chromium/media/audio/sounds/sounds_manager.h
blob: 7ff6aafffdc446b8e6c38a336fcd5e78d79ac629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
#define MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_

#include "base/basictypes.h"
#include "base/containers/hash_tables.h"
#include "base/strings/string_piece.h"
#include "base/threading/non_thread_safe.h"
#include "base/time/time.h"
#include "media/base/media_export.h"

namespace media {

// This class is used for reproduction of system sounds. All methods
// should be accessed from the Audio thread.
class MEDIA_EXPORT SoundsManager : public base::NonThreadSafe {
 public:
  typedef int SoundKey;

  // Creates a singleton instance of the SoundsManager.
  static void Create();

  // Removes a singleton instance of the SoundsManager.
  static void Shutdown();

  // Returns a pointer to a singleton instance of the SoundsManager.
  static SoundsManager* Get();

  // Initializes SoundsManager with the wav data for the system
  // sounds. Returns true if SoundsManager was successfully
  // initialized.
  virtual bool Initialize(SoundKey key, const base::StringPiece& data) = 0;

  // Plays sound identified by |key|, returns false if SoundsManager
  // was not properly initialized.
  virtual bool Play(SoundKey key) = 0;

  // Returns duration of the sound identified by |key|. If SoundsManager
  // was not properly initialized or |key| was not registered, this
  // method returns an empty value.
  virtual base::TimeDelta GetDuration(SoundKey key) = 0;

 protected:
  SoundsManager();
  virtual ~SoundsManager();

 private:
  DISALLOW_COPY_AND_ASSIGN(SoundsManager);
};

}  // namespace media

#endif  // MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_