2013-12-17 00:52:13 +00:00
|
|
|
// Copyright (c) 2013 Google Inc. 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_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
|
|
|
|
#define MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
|
|
|
|
|
2014-01-14 04:52:05 +00:00
|
|
|
#include "base/basictypes.h"
|
2013-12-17 00:52:13 +00:00
|
|
|
#include "media/base/encryptor_source.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
2014-01-14 04:52:05 +00:00
|
|
|
class RequestSigner;
|
|
|
|
|
2013-12-17 00:52:13 +00:00
|
|
|
// Defines an encryptor source which talks to Widevine encryption server.
|
|
|
|
class WidevineEncryptorSource : public EncryptorSource {
|
|
|
|
public:
|
|
|
|
enum TrackType {
|
|
|
|
TRACK_TYPE_UNKNOWN = 0,
|
|
|
|
TRACK_TYPE_SD,
|
|
|
|
TRACK_TYPE_HD,
|
|
|
|
TRACK_TYPE_AUDIO
|
|
|
|
};
|
|
|
|
|
2014-01-14 04:52:05 +00:00
|
|
|
// Caller transfers the ownership of |signer|, which should not be NULL.
|
2013-12-17 00:52:13 +00:00
|
|
|
WidevineEncryptorSource(const std::string& server_url,
|
|
|
|
const std::string& content_id,
|
2014-01-14 04:52:05 +00:00
|
|
|
TrackType track_type,
|
|
|
|
scoped_ptr<RequestSigner> signer);
|
|
|
|
virtual ~WidevineEncryptorSource();
|
2013-12-17 00:52:13 +00:00
|
|
|
|
|
|
|
// EncryptorSource implementation.
|
|
|
|
virtual Status Initialize() OVERRIDE;
|
|
|
|
|
2014-01-14 04:52:05 +00:00
|
|
|
static WidevineEncryptorSource::TrackType GetTrackTypeFromString(
|
|
|
|
const std::string& track_type_string);
|
|
|
|
|
2013-12-17 00:52:13 +00:00
|
|
|
private:
|
|
|
|
// Fill |request| with necessary fields for Widevine encryption request.
|
|
|
|
// |request| should not be NULL.
|
|
|
|
void FillRequest(const std::string& content_id, std::string* request);
|
|
|
|
// Sign and properly format |request|.
|
|
|
|
// |signed_request| should not be NULL. Return OK on success.
|
|
|
|
Status SignRequest(const std::string& request, std::string* signed_request);
|
|
|
|
// Decode |response| from JSON formatted |raw_response|.
|
|
|
|
// |response| should not be NULL.
|
|
|
|
bool DecodeResponse(const std::string& raw_response, std::string* response);
|
|
|
|
bool IsExpectedTrackType(const std::string& track_type_string);
|
|
|
|
// Extract encryption key from |response|, which is expected to be properly
|
2014-01-14 18:36:41 +00:00
|
|
|
// formatted. |transient_error| will be set to true if it fails and the
|
|
|
|
// failure is because of a transient error from the server. |transient_error|
|
|
|
|
// should not be NULL.
|
2013-12-17 00:52:13 +00:00
|
|
|
bool ExtractEncryptionKey(const std::string& response,
|
2014-01-14 18:36:41 +00:00
|
|
|
bool* transient_error);
|
2013-12-17 00:52:13 +00:00
|
|
|
|
|
|
|
std::string server_url_;
|
|
|
|
std::string content_id_;
|
|
|
|
TrackType track_type_;
|
2014-01-14 04:52:05 +00:00
|
|
|
scoped_ptr<RequestSigner> signer_;
|
2013-12-17 00:52:13 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptorSource);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif // MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
|