[M49_2623] Chromium upversion to m49_2623 branch.
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / media / base / tizen / webaudio_decoder_browser_capi.h
1 // Copyright 2015 Samsung Electronics Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_BASE_TIZEN_WEBAUDIO_DECODER_BROWSER_CAPI_H_
6 #define MEDIA_BASE_TIZEN_WEBAUDIO_DECODER_BROWSER_CAPI_H_
7
8 #include <player.h>
9 #include <player_internal.h>
10
11 #include "base/memory/singleton.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/threading/thread.h"
14 #include "media/base/efl/webaudio_decoder_efl.h"
15 #include "media/base/media_export.h"
16
17 namespace media {
18
19 struct WAPCMdata;
20
21 // WebAudioDecoderCapi class
22 class MEDIA_EXPORT WebAudioDecoderCapi : public WebAudioDecoder {
23  public:
24   static WebAudioDecoderCapi* GetInstance();
25   virtual ~WebAudioDecoderCapi();
26
27   // media::WebAudioDecoder implementation.
28   void EncodedDataReceived(base::SharedMemoryHandle memory_handle,
29                            base::FileDescriptor pcm_output,
30                            uint32_t data_size) override;
31
32  private:
33   friend struct base::DefaultSingletonTraits<WebAudioDecoderCapi>;
34   WebAudioDecoderCapi();
35   void DecodeUsingCAPI(base::SharedMemoryHandle foreign_memory_handle,
36                        base::FileDescriptor pcm_output,
37                        uint32_t data_size);
38
39   base::Thread capi_thread_;
40
41   DISALLOW_COPY_AND_ASSIGN(WebAudioDecoderCapi);
42 };
43
44 class AudioDecoderCapi {
45  public:
46   AudioDecoderCapi(base::FileDescriptor pcm_output, uint8_t* data,
47                    uint32_t data_size);
48   virtual ~AudioDecoderCapi();
49   void OnPlayerPrepared();
50   void OnPlayerDecodedBufferReady(player_audio_raw_data_s* pcm_data);
51   void OnPlayerEos();
52   void OnPlayerError(int error_code, const char* msg);
53   void OnStartDecodeProcess();
54
55  private:
56   void InitializePlayer();
57   void StartDecodeProcess();
58
59   void PlayerPrepared();
60   void PlayerDecodedBufferReady(WAPCMdata* pcm_data);
61   void PlayerEos();
62   void PlayerError(int error_code, const char* msg);
63
64  private:
65   base::Thread decoder_thread_;
66
67   // CAPI player handle.
68   player_h player_;
69
70   // The audio file information and decoded pcm data are written to
71   // this file descriptor. We take ownership of this descriptor.
72   int pcm_output_;
73
74   // The length of the encoded data.
75   uint32_t data_size_;
76
77   // Encoded audio data.
78   uint8_t* encoded_data_;
79
80   bool is_new_request_;
81   bool is_running_;
82 };
83
84 }  // namespace media
85
86 #endif  // MEDIA_BASE_TIZEN_WEBAUDIO_DECODER_BROWSER_CAPI_H_