1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
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 #ifndef FRAMEWORKS_INNERKITSIMPL_STREAM_INCLUDE_INCREMENTAL_SOURCE_STREAM_H
17 #define FRAMEWORKS_INNERKITSIMPL_STREAM_INCLUDE_INCREMENTAL_SOURCE_STREAM_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <vector>
22 #include "image/input_data_stream.h"
23 #include "image_type.h"
24 #include "source_stream.h"
25 
26 namespace OHOS {
27 namespace Media {
28 class IncrementalSourceStream : public SourceStream {
29 public:
30     static std::unique_ptr<IncrementalSourceStream> CreateSourceStream(IncrementalMode mode);
31     explicit IncrementalSourceStream(IncrementalMode mode);
32     ~IncrementalSourceStream() = default;
33     bool Read(uint32_t desiredSize, ImagePlugin::DataStreamBuffer &outData) override;
34     bool Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize) override;
35     bool Peek(uint32_t desiredSize, ImagePlugin::DataStreamBuffer &outData) override;
36     bool Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize) override;
37     uint32_t Tell() override;
38     bool Seek(uint32_t position) override;
39 
40     uint32_t UpdateData(const uint8_t *data, uint32_t size, bool isCompleted) override;
41     bool IsStreamCompleted() override;
42     size_t GetStreamSize() override;
43     uint8_t *GetDataPtr() override;
44 private:
45     IncrementalMode incrementalMode_;
46     bool isFinalize_;
47     std::vector<uint8_t> sourceData_;
48     size_t dataSize_ = 0;
49     size_t dataOffset_ = 0;
50 };
51 } // namespace Media
52 } // namespace OHOS
53 
54 #endif // FRAMEWORKS_INNERKITSIMPL_STREAM_INCLUDE_INCREMENTAL_SOURCE_STREAM_H
55