b9e6cc781743a1b8b71900002d729c09e3ebff1d
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2016 Samsung Electronics. 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_TIZEN_PEPPER_TIZEN_DRM_SESSION_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_TIZEN_PEPPER_TIZEN_DRM_SESSION_H_
7
8 #include <drmdecrypt_api.h>
9 #include <emeCDM/IEME.h>
10 #include <memory>
11
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "ppapi/c/samsung/pp_media_player_samsung.h"
15 #include "ppapi/shared_impl/media_player/es_packet.h"
16
17 namespace content {
18
19 class PepperTizenDRMListener;
20
21 struct HandleAndSizeDeleter {
22   void operator()(handle_and_size_s* ptr) const;
23 };
24
25 using ScopedHandleAndSize =
26     std::unique_ptr<handle_and_size_s, HandleAndSizeDeleter>;
27
28 class PepperTizenDRMSession
29     : public base::RefCountedThreadSafe<PepperTizenDRMSession>,
30       public base::SupportsWeakPtr<PepperTizenDRMSession> {
31  public:
32   static scoped_refptr<PepperTizenDRMSession> Create(PP_MediaPlayerDRMType,
33                                                      eme::IEventListener*);
34
35   ~PepperTizenDRMSession();
36
37   bool Initialize(const std::string& init_data);
38
39   ScopedHandleAndSize Decrypt(const ppapi::EncryptedESPacket&);
40
41   bool InstallLicense(const std::string& response);
42
43   bool is_valid() const { return !session_id_.empty(); }
44
45   std::string session_id() const { return session_id_; }
46
47  private:
48   friend class scoped_refptr<PepperTizenDRMSession>;
49   PepperTizenDRMSession(PP_MediaPlayerDRMType drm_type,
50                         const std::string& keysystem_name,
51                         eme::IEventListener* listener);
52
53   PP_MediaPlayerDRMType drm_type_;
54   std::string session_id_;
55   std::unique_ptr<eme::IEME, decltype(&eme::IEME::destroy)> ieme_;
56
57   bool InitializeSession();
58 };
59
60 ScopedHandleAndSize AdoptHandle(handle_and_size_s* handle_and_size);
61
62 void ClearHandle(handle_and_size_s* handle_and_size);
63
64 }  // namespace content
65
66 #endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_TIZEN_PEPPER_TIZEN_DRM_SESSION_H_