Scanner C++ API
h264_byte_stream_index_creator.h
1 /* Copyright 2016 Carnegie Mellon University
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include "scanner/api/database.h"
19 #include "scanner/util/common.h"
20 #include "scanner/util/h264.h"
21 
22 #include "storehouse/storage_backend.h"
23 #include "storehouse/storage_config.h"
24 
25 #include <string>
26 
27 namespace scanner {
28 namespace internal {
29 
31  public:
32  H264ByteStreamIndexCreator(storehouse::WriteFile* demuxed_bytestream);
33 
34  bool feed_packet(u8* data, size_t size);
35 
36  const std::vector<u8>& metadata_bytes() { return metadata_bytes_; }
37  const std::vector<u64>& sample_offsets() { return sample_offsets_; }
38  const std::vector<u64>& sample_sizes() { return sample_sizes_; }
39  const std::vector<u64>& keyframe_indices() { return keyframe_indices_; }
40 
41  i32 frames() { return frame_; };
42  i32 num_non_ref_frames() { return num_non_ref_frames_; };
43  i32 nals_parsed() { return nals_parsed_; };
44  i64 bytestream_pos() { return bytestream_pos_; }
45 
46  std::string error_message() { return error_message_; }
47 
48  private:
49  std::string error_message_;
50 
51  storehouse::WriteFile* demuxed_bytestream_;
52 
53  u64 bytestream_pos_ = 0;
54  std::vector<u8> metadata_bytes_;
55  std::vector<u64> sample_offsets_;
56  std::vector<u64> sample_sizes_;
57  std::vector<u64> keyframe_indices_;
58 
59  i64 frame_ = 0;
60  bool in_meta_packet_sequence_ = false;
61  i64 meta_packet_sequence_start_offset_ = 0;
62  bool saw_sps_nal_ = false;
63  bool saw_pps_nal_ = false;
64  std::map<u32, SPS> sps_map_;
65  std::map<u32, PPS> pps_map_;
66  u32 last_sps_ = -1;
67  u32 last_pps_ = -1;
68  std::map<u32, std::vector<u8>> sps_nal_bytes_;
69  std::map<u32, std::vector<u8>> pps_nal_bytes_;
70  SliceHeader prev_sh_;
71 
72  i32 num_non_ref_frames_ = 0;
73  i32 nals_parsed_ = 0;
74 };
75 }
76 }
Definition: database.cpp:36
Definition: h264_byte_stream_index_creator.h:30
Definition: h264.h:296