* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INPUT_DATA_STREAM_H
#define INPUT_DATA_STREAM_H
#include <cstdint>
#include "nocopyable.h"
#include "output_data_stream.h"
namespace OHOS {
namespace ImagePlugin {
enum {
BUFFER_SOURCE_TYPE,
INPUT_STREAM_TYPE,
FILE_STREAM_TYPE,
};
struct DataStreamBuffer {
const uint8_t *inputStreamBuffer = nullptr;
uint32_t bufferSize = 0;
uint32_t dataSize = 0;
};
class InputDataStream : NoCopyable {
public:
virtual bool Read(uint32_t desiredSize, DataStreamBuffer &outData) = 0;
virtual bool Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize) = 0;
virtual bool Peek(uint32_t desiredSize, DataStreamBuffer &outData) = 0;
virtual bool Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize) = 0;
virtual uint32_t Tell() = 0;
virtual bool Seek(uint32_t position) = 0;
virtual uint32_t GetStreamType()
{
return -1;
}
virtual uint8_t *GetDataPtr()
{
return nullptr;
}
virtual uint8_t *GetDataPtr(bool populate)
{
return nullptr;
}
virtual bool IsStreamCompleted()
{
return true;
}
virtual size_t GetStreamSize()
{
return 0;
}
virtual OutputDataStream* ToOutputDataStream()
{
return nullptr;
}
virtual ~InputDataStream() {}
};
}
}
#endif