|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <cstdint> |
| 4 | +#include <cstddef> |
| 5 | +#include <vector> |
| 6 | +#include <functional> |
| 7 | +#include <typeinfo> |
| 8 | + |
| 9 | +namespace cdm { struct InputBuffer_2; } |
| 10 | +namespace wvcdm { struct InputBuffer; } |
| 11 | + |
| 12 | +namespace svp |
| 13 | +{ |
| 14 | +class InbandSerializerImpl |
| 15 | +{ |
| 16 | + public: |
| 17 | + virtual ~InbandSerializerImpl() = default; |
| 18 | + virtual bool DoConfigure(const uint8_t*, size_t, |
| 19 | + const std::function<bool(std::vector<uint8_t>*,void*)>&, |
| 20 | + void*) = 0; |
| 21 | + bool DoSerialize(std::vector<uint8_t>*); |
| 22 | +}; |
| 23 | + |
| 24 | +// pulled in from stub or the real .so at link time |
| 25 | +std::shared_ptr<InbandSerializerImpl> CreateInbandSerializerImpl(void*, const std::type_info&); |
| 26 | + |
| 27 | +template<typename T> |
| 28 | +class InbandSerializer |
| 29 | +{ |
| 30 | +public: |
| 31 | + InbandSerializer() |
| 32 | + : impl_(CreateInbandSerializerImpl(static_cast<void*>(this), typeid(T))) |
| 33 | + {} |
| 34 | + |
| 35 | + ~InbandSerializer() |
| 36 | + {} |
| 37 | + |
| 38 | + /** |
| 39 | + * @param obj current instance of InbandSerializerImplReal<bool> |
| 40 | + * @param data raw media buffer |
| 41 | + * @param size size of media buffer |
| 42 | + * @param callBack callback to configure output vector |
| 43 | + * @param context opaque user context |
| 44 | + */ |
| 45 | + bool Configure(const T &obj, |
| 46 | + const uint8_t *data, |
| 47 | + uint32_t size, |
| 48 | + const std::function<bool(std::vector<uint8_t>*,void*)>&callBack = nullptr, |
| 49 | + void *context = nullptr) |
| 50 | + { |
| 51 | + if (!impl_) return false; |
| 52 | + obj_ = obj; |
| 53 | + return impl_->DoConfigure(data, size, callBack, context); |
| 54 | + } |
| 55 | + |
| 56 | + bool GetSerialized(std::vector<uint8_t>* out) |
| 57 | + { |
| 58 | + if (!impl_ || !out) return false; |
| 59 | + return impl_->DoSerialize(out); |
| 60 | + } |
| 61 | + |
| 62 | + bool CanDoSerialize() { return impl_ != nullptr; } |
| 63 | + |
| 64 | + const T& encryption_info() const { return obj_; } |
| 65 | + |
| 66 | +private: |
| 67 | + T obj_; |
| 68 | + std::shared_ptr<InbandSerializerImpl> impl_; |
| 69 | + |
| 70 | + void operator=(const InbandSerializer&); |
| 71 | +}; |
| 72 | + |
| 73 | +} // namespace svp |
0 commit comments