1 // Copyright 2014 The Chromium Authors. 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.
5 #ifndef MEDIA_CAST_TEST_UTILITY_BARCODE_H_
6 #define MEDIA_CAST_TEST_UTILITY_BARCODE_H_
10 #include "base/memory/ref_counted.h"
17 // Encode a resilient barcode into |frame| containing all the bits
19 bool EncodeBarcode(const std::vector
<bool>& bits
,
20 scoped_refptr
<media::VideoFrame
> output_frame
);
21 // Decode a barcode (encoded by EncodeBarCode) into |output|.
22 // |output| should already be sized to contain the right number
24 bool DecodeBarcode(const scoped_refptr
<media::VideoFrame
>& frame
,
25 std::vector
<bool>* output
);
27 // Convenience templates that allows you to encode/decode numeric
30 bool EncodeBarcode(T data
, scoped_refptr
<media::VideoFrame
> output_frame
) {
31 std::vector
<bool> bits(sizeof(T
) * 8);
32 for (size_t i
= 0; i
< bits
.size(); i
++) {
33 bits
[i
] = ((data
>> i
) & 1) == 1;
35 return EncodeBarcode(bits
, output_frame
);
39 bool DecodeBarcode(scoped_refptr
<media::VideoFrame
> output_frame
, T
* data
) {
40 std::vector
<bool> bits(sizeof(T
) * 8);
41 bool ret
= DecodeBarcode(output_frame
, &bits
);
42 if (!ret
) return false;
44 for (size_t i
= 0; i
< bits
.size(); i
++) {
56 #endif // MEDIA_CAST_TEST_UTILITY_BARCODE_H_