2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-03-24 02:03:53 +01:00
|
|
|
//
|
|
|
|
// This code is licensed under the same terms as WebM:
|
|
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Incremental decoding
|
|
|
|
//
|
|
|
|
// Author: somnath@google.com (Somnath Banerjee)
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-12-01 11:00:03 +01:00
|
|
|
#include "./webpi.h"
|
|
|
|
#include "./vp8i.h"
|
2011-03-24 02:03:53 +01:00
|
|
|
|
2011-03-24 02:41:18 +01:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-02-08 03:49:26 +01:00
|
|
|
// In append mode, buffer allocations increase as multiples of this value.
|
|
|
|
// Needs to be a power of 2.
|
2011-03-24 02:03:53 +01:00
|
|
|
#define CHUNK_SIZE 4096
|
|
|
|
#define MAX_MB_SIZE 4096
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Data structures for memory and states
|
|
|
|
|
|
|
|
// Decoding states. State normally flows like HEADER->PARTS0->DATA->DONE.
|
|
|
|
// If there is any error the decoder goes into state ERROR.
|
2011-09-13 11:35:10 +02:00
|
|
|
typedef enum {
|
|
|
|
STATE_PRE_VP8, // All data before that of the first VP8 chunk.
|
|
|
|
STATE_VP8_FRAME_HEADER, // For VP8 Frame header (within VP8 chunk).
|
|
|
|
STATE_VP8_PARTS0,
|
|
|
|
STATE_VP8_DATA,
|
2012-04-11 03:41:18 +02:00
|
|
|
STATE_VP8L_HEADER,
|
|
|
|
STATE_VP8L_DATA,
|
2011-09-13 11:35:10 +02:00
|
|
|
STATE_DONE,
|
|
|
|
STATE_ERROR
|
2011-03-24 02:03:53 +01:00
|
|
|
} DecState;
|
|
|
|
|
|
|
|
// Operating state for the MemBuffer
|
2011-09-13 11:35:10 +02:00
|
|
|
typedef enum {
|
|
|
|
MEM_MODE_NONE = 0,
|
|
|
|
MEM_MODE_APPEND,
|
|
|
|
MEM_MODE_MAP
|
2011-03-24 02:03:53 +01:00
|
|
|
} MemBufferMode;
|
|
|
|
|
|
|
|
// storage for partition #0 and partial data (in a rolling fashion)
|
|
|
|
typedef struct {
|
|
|
|
MemBufferMode mode_; // Operation mode
|
|
|
|
uint32_t start_; // start location of the data to be decoded
|
|
|
|
uint32_t end_; // end location
|
|
|
|
size_t buf_size_; // size of the allocated buffer
|
|
|
|
uint8_t* buf_; // We don't own this buffer in case WebPIUpdate()
|
|
|
|
|
|
|
|
size_t part0_size_; // size of partition #0
|
|
|
|
const uint8_t* part0_buf_; // buffer to store partition #0
|
|
|
|
} MemBuffer;
|
|
|
|
|
|
|
|
struct WebPIDecoder {
|
|
|
|
DecState state_; // current decoding state
|
|
|
|
WebPDecParams params_; // Params to store output info
|
2012-04-05 11:31:10 +02:00
|
|
|
int is_lossless_; // for down-casting 'dec_'.
|
|
|
|
void* dec_; // either a VP8Decoder or a VP8LDecoder instance
|
2011-03-24 02:03:53 +01:00
|
|
|
VP8Io io_;
|
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
MemBuffer mem_; // input memory buffer.
|
|
|
|
WebPDecBuffer output_; // output buffer (when no external one is supplied)
|
2012-04-05 11:31:10 +02:00
|
|
|
uint32_t chunk_size_; // Compressed VP8/VP8L size extracted from Header.
|
2011-03-24 02:03:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// MB context to restore in case VP8DecodeMB() fails
|
|
|
|
typedef struct {
|
|
|
|
VP8MB left_;
|
|
|
|
VP8MB info_;
|
|
|
|
uint8_t intra_t_[4];
|
|
|
|
uint8_t intra_l_[4];
|
|
|
|
VP8BitReader br_;
|
|
|
|
VP8BitReader token_br_;
|
|
|
|
} MBContext;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// MemBuffer: incoming data handling
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
static void RemapBitReader(VP8BitReader* const br, ptrdiff_t offset) {
|
|
|
|
if (br->buf_ != NULL) {
|
|
|
|
br->buf_ += offset;
|
|
|
|
br->buf_end_ += offset;
|
|
|
|
}
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
|
2011-11-05 03:44:57 +01:00
|
|
|
static WEBP_INLINE size_t MemDataSize(const MemBuffer* mem) {
|
2011-03-24 02:03:53 +01:00
|
|
|
return (mem->end_ - mem->start_);
|
|
|
|
}
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
|
|
|
|
MemBuffer* const mem = &idec->mem_;
|
|
|
|
const uint8_t* const new_base = mem->buf_ + mem->start_;
|
|
|
|
// note: for VP8, setting up idec->io_ is only really needed at the beginning
|
|
|
|
// of the decoding, till partition #0 is complete.
|
|
|
|
idec->io_.data = new_base;
|
|
|
|
idec->io_.data_size = MemDataSize(mem);
|
|
|
|
|
|
|
|
if (idec->dec_ != NULL) {
|
|
|
|
if (!idec->is_lossless_) {
|
|
|
|
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
|
|
|
const int last_part = dec->num_parts_ - 1;
|
|
|
|
if (offset != 0) {
|
|
|
|
int p;
|
|
|
|
for (p = 0; p <= last_part; ++p) {
|
|
|
|
RemapBitReader(dec->parts_ + p, offset);
|
|
|
|
}
|
|
|
|
// Remap partition #0 data pointer to new offset, but only in MAP
|
|
|
|
// mode (in APPEND mode, partition #0 is copied into a fixed memory).
|
|
|
|
if (mem->mode_ == MEM_MODE_MAP) {
|
|
|
|
RemapBitReader(&dec->br_, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(last_part >= 0);
|
|
|
|
dec->parts_[last_part].buf_end_ = mem->buf_ + mem->end_;
|
|
|
|
} else { // Resize lossless bitreader
|
|
|
|
VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
|
|
|
|
VP8LBitReaderSetBuffer(&dec->br_, new_base, MemDataSize(mem));
|
|
|
|
}
|
2012-04-11 03:41:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 02:03:53 +01:00
|
|
|
// Appends data to the end of MemBuffer->buf_. It expands the allocated memory
|
|
|
|
// size if required and also updates VP8BitReader's if new memory is allocated.
|
|
|
|
static int AppendToMemBuffer(WebPIDecoder* const idec,
|
|
|
|
const uint8_t* const data, size_t data_size) {
|
|
|
|
MemBuffer* const mem = &idec->mem_;
|
2012-04-05 11:31:10 +02:00
|
|
|
const uint8_t* const old_base = mem->buf_ + mem->start_;
|
2011-03-24 02:03:53 +01:00
|
|
|
assert(mem->mode_ == MEM_MODE_APPEND);
|
|
|
|
|
|
|
|
if (mem->end_ + data_size > mem->buf_size_) { // Need some free memory
|
2012-04-05 11:31:10 +02:00
|
|
|
const size_t current_size = MemDataSize(mem);
|
|
|
|
const size_t new_size = current_size + data_size;
|
|
|
|
const size_t extra_size = (new_size + CHUNK_SIZE - 1) & ~(CHUNK_SIZE - 1);
|
|
|
|
uint8_t* const new_buf = (uint8_t*)malloc(extra_size);
|
2012-02-08 03:49:26 +01:00
|
|
|
if (new_buf == NULL) return 0;
|
2012-04-05 11:31:10 +02:00
|
|
|
memcpy(new_buf, old_base, current_size);
|
2011-03-24 02:03:53 +01:00
|
|
|
free(mem->buf_);
|
|
|
|
mem->buf_ = new_buf;
|
2012-04-05 11:31:10 +02:00
|
|
|
mem->buf_size_ = extra_size;
|
2011-03-24 02:03:53 +01:00
|
|
|
mem->start_ = 0;
|
2012-04-05 11:31:10 +02:00
|
|
|
mem->end_ = current_size;
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(mem->buf_ + mem->end_, data, data_size);
|
|
|
|
mem->end_ += data_size;
|
|
|
|
assert(mem->end_ <= mem->buf_size_);
|
2012-04-11 03:41:18 +02:00
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
DoRemap(idec, mem->buf_ + mem->start_ - old_base);
|
2011-03-24 02:03:53 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int RemapMemBuffer(WebPIDecoder* const idec,
|
|
|
|
const uint8_t* const data, size_t data_size) {
|
|
|
|
MemBuffer* const mem = &idec->mem_;
|
2012-04-05 11:31:10 +02:00
|
|
|
const uint8_t* const old_base = mem->buf_ + mem->start_;
|
2011-03-24 02:03:53 +01:00
|
|
|
assert(mem->mode_ == MEM_MODE_MAP);
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
if (data_size < mem->buf_size_) return 0; // can't remap to a shorter buffer!
|
2011-03-24 02:03:53 +01:00
|
|
|
|
|
|
|
mem->buf_ = (uint8_t*)data;
|
|
|
|
mem->end_ = mem->buf_size_ = data_size;
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
DoRemap(idec, mem->buf_ + mem->start_ - old_base);
|
2011-03-24 02:03:53 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitMemBuffer(MemBuffer* const mem) {
|
|
|
|
mem->mode_ = MEM_MODE_NONE;
|
2012-04-05 11:31:10 +02:00
|
|
|
mem->buf_ = NULL;
|
2011-03-24 02:03:53 +01:00
|
|
|
mem->buf_size_ = 0;
|
2012-04-05 11:31:10 +02:00
|
|
|
mem->part0_buf_ = NULL;
|
2011-03-24 02:03:53 +01:00
|
|
|
mem->part0_size_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearMemBuffer(MemBuffer* const mem) {
|
|
|
|
assert(mem);
|
|
|
|
if (mem->mode_ == MEM_MODE_APPEND) {
|
|
|
|
free(mem->buf_);
|
|
|
|
free((void*)mem->part0_buf_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CheckMemBufferMode(MemBuffer* const mem, MemBufferMode expected) {
|
|
|
|
if (mem->mode_ == MEM_MODE_NONE) {
|
|
|
|
mem->mode_ = expected; // switch to the expected mode
|
|
|
|
} else if (mem->mode_ != expected) {
|
|
|
|
return 0; // we mixed the modes => error
|
|
|
|
}
|
|
|
|
assert(mem->mode_ == expected); // mode is ok
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Macroblock-decoding contexts
|
|
|
|
|
|
|
|
static void SaveContext(const VP8Decoder* dec, const VP8BitReader* token_br,
|
|
|
|
MBContext* const context) {
|
|
|
|
const VP8BitReader* const br = &dec->br_;
|
|
|
|
const VP8MB* const left = dec->mb_info_ - 1;
|
|
|
|
const VP8MB* const info = dec->mb_info_ + dec->mb_x_;
|
|
|
|
|
|
|
|
context->left_ = *left;
|
|
|
|
context->info_ = *info;
|
|
|
|
context->br_ = *br;
|
|
|
|
context->token_br_ = *token_br;
|
|
|
|
memcpy(context->intra_t_, dec->intra_t_ + 4 * dec->mb_x_, 4);
|
|
|
|
memcpy(context->intra_l_, dec->intra_l_, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RestoreContext(const MBContext* context, VP8Decoder* const dec,
|
|
|
|
VP8BitReader* const token_br) {
|
|
|
|
VP8BitReader* const br = &dec->br_;
|
|
|
|
VP8MB* const left = dec->mb_info_ - 1;
|
|
|
|
VP8MB* const info = dec->mb_info_ + dec->mb_x_;
|
|
|
|
|
|
|
|
*left = context->left_;
|
|
|
|
*info = context->info_;
|
|
|
|
*br = context->br_;
|
|
|
|
*token_br = context->token_br_;
|
|
|
|
memcpy(dec->intra_t_ + 4 * dec->mb_x_, context->intra_t_, 4);
|
|
|
|
memcpy(dec->intra_l_, context->intra_l_, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2011-09-16 21:07:55 +02:00
|
|
|
static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) {
|
2011-09-13 11:35:10 +02:00
|
|
|
if (idec->state_ == STATE_VP8_DATA) {
|
2011-07-20 16:49:57 +02:00
|
|
|
VP8Io* const io = &idec->io_;
|
|
|
|
if (io->teardown) {
|
|
|
|
io->teardown(io);
|
|
|
|
}
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
idec->state_ = STATE_ERROR;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-09-16 21:07:55 +02:00
|
|
|
static void ChangeState(WebPIDecoder* const idec, DecState new_state,
|
2011-09-13 11:35:10 +02:00
|
|
|
uint32_t consumed_bytes) {
|
2012-04-05 11:31:10 +02:00
|
|
|
MemBuffer* const mem = &idec->mem_;
|
2011-09-13 11:35:10 +02:00
|
|
|
idec->state_ = new_state;
|
2012-04-05 11:31:10 +02:00
|
|
|
mem->start_ += consumed_bytes;
|
|
|
|
assert(mem->start_ <= mem->end_);
|
|
|
|
idec->io_.data = mem->buf_ + mem->start_;
|
|
|
|
idec->io_.data_size = MemDataSize(mem);
|
2011-09-13 11:35:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Headers
|
|
|
|
static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) {
|
2012-04-05 11:31:10 +02:00
|
|
|
MemBuffer* const mem = &idec->mem_;
|
|
|
|
const uint8_t* data = mem->buf_ + mem->start_;
|
|
|
|
uint32_t curr_size = MemDataSize(mem);
|
2011-09-13 11:35:10 +02:00
|
|
|
VP8StatusCode status;
|
2012-04-11 03:41:18 +02:00
|
|
|
WebPHeaderStructure headers;
|
2011-08-18 20:07:13 +02:00
|
|
|
|
2012-04-11 03:41:18 +02:00
|
|
|
headers.data = data;
|
|
|
|
headers.data_size = curr_size;
|
|
|
|
status = WebPParseHeaders(&headers);
|
2011-09-13 11:35:10 +02:00
|
|
|
if (status == VP8_STATUS_NOT_ENOUGH_DATA) {
|
|
|
|
return VP8_STATUS_SUSPENDED; // We haven't found a VP8 chunk yet.
|
2012-04-05 11:31:10 +02:00
|
|
|
} else if (status != VP8_STATUS_OK) {
|
|
|
|
return IDecError(idec, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
idec->chunk_size_ = headers.vp8_size;
|
|
|
|
idec->is_lossless_ = headers.is_lossless;
|
|
|
|
if (!idec->is_lossless_) {
|
|
|
|
VP8Decoder* const dec = VP8New();
|
|
|
|
if (dec == NULL) {
|
|
|
|
return VP8_STATUS_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
idec->dec_ = dec;
|
|
|
|
#ifdef WEBP_USE_THREAD
|
|
|
|
dec->use_threads_ = (idec->params_.options != NULL) &&
|
|
|
|
(idec->params_.options->use_threads > 0);
|
|
|
|
#else
|
|
|
|
dec->use_threads_ = 0;
|
|
|
|
#endif
|
2012-04-11 03:41:18 +02:00
|
|
|
dec->alpha_data_ = headers.alpha_data;
|
|
|
|
dec->alpha_data_size_ = headers.alpha_data_size;
|
2012-04-05 11:31:10 +02:00
|
|
|
ChangeState(idec, STATE_VP8_FRAME_HEADER, headers.offset);
|
2011-09-13 11:35:10 +02:00
|
|
|
} else {
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8LDecoder* const dec = VP8LNew();
|
|
|
|
if (dec == NULL) {
|
|
|
|
return VP8_STATUS_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
idec->dec_ = dec;
|
|
|
|
ChangeState(idec, STATE_VP8L_HEADER, headers.offset);
|
2011-08-18 20:07:13 +02:00
|
|
|
}
|
2012-04-05 11:31:10 +02:00
|
|
|
return VP8_STATUS_OK;
|
2011-09-13 11:35:10 +02:00
|
|
|
}
|
2011-08-18 20:07:13 +02:00
|
|
|
|
2011-09-13 11:35:10 +02:00
|
|
|
static VP8StatusCode DecodeVP8FrameHeader(WebPIDecoder* const idec) {
|
|
|
|
const uint8_t* data = idec->mem_.buf_ + idec->mem_.start_;
|
2011-09-16 21:07:55 +02:00
|
|
|
const uint32_t curr_size = MemDataSize(&idec->mem_);
|
2011-09-13 11:35:10 +02:00
|
|
|
uint32_t bits;
|
2011-08-18 20:07:13 +02:00
|
|
|
|
2011-09-13 11:35:10 +02:00
|
|
|
if (curr_size < VP8_FRAME_HEADER_SIZE) {
|
|
|
|
// Not enough data bytes to extract VP8 Frame Header.
|
|
|
|
return VP8_STATUS_SUSPENDED;
|
2011-08-18 20:07:13 +02:00
|
|
|
}
|
2012-04-05 11:31:10 +02:00
|
|
|
if (!VP8GetInfo(data, curr_size, idec->chunk_size_, NULL, NULL)) {
|
2011-03-24 02:03:53 +01:00
|
|
|
return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
|
|
|
|
}
|
2011-06-20 09:45:15 +02:00
|
|
|
|
2011-03-24 02:03:53 +01:00
|
|
|
bits = data[0] | (data[1] << 8) | (data[2] << 16);
|
2011-09-13 11:35:10 +02:00
|
|
|
idec->mem_.part0_size_ = (bits >> 5) + VP8_FRAME_HEADER_SIZE;
|
2011-03-24 02:03:53 +01:00
|
|
|
|
|
|
|
idec->io_.data = data;
|
2012-04-05 11:31:10 +02:00
|
|
|
idec->io_.data_size = curr_size;
|
2011-09-13 11:35:10 +02:00
|
|
|
idec->state_ = STATE_VP8_PARTS0;
|
2011-03-24 02:03:53 +01:00
|
|
|
return VP8_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Partition #0
|
2012-04-05 11:31:10 +02:00
|
|
|
static int CopyParts0Data(WebPIDecoder* const idec) {
|
|
|
|
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
|
|
|
VP8BitReader* const br = &dec->br_;
|
2011-03-24 02:03:53 +01:00
|
|
|
const size_t psize = br->buf_end_ - br->buf_;
|
|
|
|
MemBuffer* const mem = &idec->mem_;
|
2012-04-05 11:31:10 +02:00
|
|
|
assert(!idec->is_lossless_);
|
2011-03-24 02:03:53 +01:00
|
|
|
assert(!mem->part0_buf_);
|
|
|
|
assert(psize > 0);
|
|
|
|
assert(psize <= mem->part0_size_);
|
|
|
|
if (mem->mode_ == MEM_MODE_APPEND) {
|
|
|
|
// We copy and grab ownership of the partition #0 data.
|
|
|
|
uint8_t* const part0_buf = (uint8_t*)malloc(psize);
|
2012-02-08 03:49:26 +01:00
|
|
|
if (part0_buf == NULL) {
|
2011-03-24 02:03:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memcpy(part0_buf, br->buf_, psize);
|
|
|
|
mem->part0_buf_ = part0_buf;
|
|
|
|
br->buf_ = part0_buf;
|
|
|
|
br->buf_end_ = part0_buf + psize;
|
|
|
|
} else {
|
|
|
|
// Else: just keep pointers to the partition #0's data in dec_->br_.
|
|
|
|
}
|
2012-02-01 00:26:35 +01:00
|
|
|
mem->start_ += psize;
|
2011-03-24 02:03:53 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VP8StatusCode DecodePartition0(WebPIDecoder* const idec) {
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
2011-03-24 02:03:53 +01:00
|
|
|
VP8Io* const io = &idec->io_;
|
|
|
|
const WebPDecParams* const params = &idec->params_;
|
2011-06-20 09:45:15 +02:00
|
|
|
WebPDecBuffer* const output = params->output;
|
2011-03-24 02:03:53 +01:00
|
|
|
|
|
|
|
// Wait till we have enough data for the whole partition #0
|
|
|
|
if (MemDataSize(&idec->mem_) < idec->mem_.part0_size_) {
|
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VP8GetHeaders(dec, io)) {
|
|
|
|
const VP8StatusCode status = dec->status_;
|
|
|
|
if (status == VP8_STATUS_SUSPENDED ||
|
|
|
|
status == VP8_STATUS_NOT_ENOUGH_DATA) {
|
|
|
|
// treating NOT_ENOUGH_DATA as SUSPENDED state
|
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
|
|
|
return IDecError(idec, status);
|
|
|
|
}
|
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
// Allocate/Verify output buffer now
|
|
|
|
dec->status_ = WebPAllocateDecBuffer(io->width, io->height, params->options,
|
|
|
|
output);
|
|
|
|
if (dec->status_ != VP8_STATUS_OK) {
|
|
|
|
return IDecError(idec, dec->status_);
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CopyParts0Data(idec)) {
|
|
|
|
return IDecError(idec, VP8_STATUS_OUT_OF_MEMORY);
|
|
|
|
}
|
2011-07-20 16:49:57 +02:00
|
|
|
|
2011-07-22 22:09:10 +02:00
|
|
|
// Finish setting up the decoding parameters. Will call io->setup().
|
|
|
|
if (VP8EnterCritical(dec, io) != VP8_STATUS_OK) {
|
2011-07-20 16:49:57 +02:00
|
|
|
return IDecError(idec, dec->status_);
|
|
|
|
}
|
2011-07-22 22:09:10 +02:00
|
|
|
|
2011-07-20 16:49:57 +02:00
|
|
|
// Note: past this point, teardown() must always be called
|
|
|
|
// in case of error.
|
2011-09-13 11:35:10 +02:00
|
|
|
idec->state_ = STATE_VP8_DATA;
|
2011-07-22 22:09:10 +02:00
|
|
|
// Allocate memory and prepare everything.
|
|
|
|
if (!VP8InitFrame(dec, io)) {
|
|
|
|
return IDecError(idec, dec->status_);
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
return VP8_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remaining partitions
|
|
|
|
static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) {
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
2011-03-24 02:03:53 +01:00
|
|
|
VP8Io* const io = &idec->io_;
|
|
|
|
|
|
|
|
assert(dec->ready_);
|
|
|
|
|
|
|
|
for (; dec->mb_y_ < dec->mb_h_; ++dec->mb_y_) {
|
|
|
|
VP8BitReader* token_br = &dec->parts_[dec->mb_y_ & (dec->num_parts_ - 1)];
|
|
|
|
if (dec->mb_x_ == 0) {
|
2011-07-22 22:09:10 +02:00
|
|
|
VP8InitScanline(dec);
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
|
|
|
for (; dec->mb_x_ < dec->mb_w_; dec->mb_x_++) {
|
|
|
|
MBContext context;
|
|
|
|
SaveContext(dec, token_br, &context);
|
|
|
|
|
|
|
|
if (!VP8DecodeMB(dec, token_br)) {
|
|
|
|
RestoreContext(&context, dec, token_br);
|
|
|
|
// We shouldn't fail when MAX_MB data was available
|
|
|
|
if (dec->num_parts_ == 1 && MemDataSize(&idec->mem_) > MAX_MB_SIZE) {
|
|
|
|
return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
|
|
|
|
}
|
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
|
|
|
VP8ReconstructBlock(dec);
|
|
|
|
// Store data and save block's filtering params
|
|
|
|
VP8StoreBlock(dec);
|
|
|
|
|
|
|
|
// Release buffer only if there is only one partition
|
|
|
|
if (dec->num_parts_ == 1) {
|
|
|
|
idec->mem_.start_ = token_br->buf_ - idec->mem_.buf_;
|
|
|
|
assert(idec->mem_.start_ <= idec->mem_.end_);
|
|
|
|
}
|
|
|
|
}
|
2011-07-22 22:09:10 +02:00
|
|
|
if (!VP8ProcessRow(dec, io)) {
|
2011-03-24 02:03:53 +01:00
|
|
|
return IDecError(idec, VP8_STATUS_USER_ABORT);
|
|
|
|
}
|
|
|
|
dec->mb_x_ = 0;
|
|
|
|
}
|
2011-07-22 22:09:10 +02:00
|
|
|
// Synchronize the thread and check for errors.
|
|
|
|
if (!VP8ExitCritical(dec, io)) {
|
|
|
|
return IDecError(idec, VP8_STATUS_USER_ABORT);
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
|
|
|
dec->ready_ = 0;
|
|
|
|
idec->state_ = STATE_DONE;
|
|
|
|
|
|
|
|
return VP8_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-11 03:41:18 +02:00
|
|
|
static int ErrorStatusLossless(WebPIDecoder* const idec, VP8StatusCode status) {
|
|
|
|
if (status == VP8_STATUS_SUSPENDED || status == VP8_STATUS_NOT_ENOUGH_DATA) {
|
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
|
|
|
return IDecError(idec, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VP8StatusCode DecodeVP8LHeader(WebPIDecoder* const idec) {
|
|
|
|
VP8Io* const io = &idec->io_;
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
|
2012-04-11 03:41:18 +02:00
|
|
|
const WebPDecParams* const params = &idec->params_;
|
|
|
|
WebPDecBuffer* const output = params->output;
|
|
|
|
uint32_t curr_size = MemDataSize(&idec->mem_);
|
2012-04-05 11:31:10 +02:00
|
|
|
assert(idec->is_lossless_);
|
2012-04-11 03:41:18 +02:00
|
|
|
|
|
|
|
// Wait until there's enough data for decoding header.
|
2012-04-05 11:31:10 +02:00
|
|
|
if (curr_size < (idec->chunk_size_ >> 3)) {
|
2012-04-11 03:41:18 +02:00
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
2012-04-05 11:31:10 +02:00
|
|
|
if (!VP8LDecodeHeader(dec, io)) {
|
|
|
|
return ErrorStatusLossless(idec, dec->status_);
|
2012-04-11 03:41:18 +02:00
|
|
|
}
|
|
|
|
// Allocate/verify output buffer now.
|
|
|
|
dec->status_ = WebPAllocateDecBuffer(io->width, io->height, params->options,
|
|
|
|
output);
|
|
|
|
if (dec->status_ != VP8_STATUS_OK) {
|
|
|
|
return IDecError(idec, dec->status_);
|
|
|
|
}
|
|
|
|
|
|
|
|
idec->state_ = STATE_VP8L_DATA;
|
|
|
|
return VP8_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VP8StatusCode DecodeVP8LData(WebPIDecoder* const idec) {
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
|
2012-04-11 03:41:18 +02:00
|
|
|
const uint32_t curr_size = MemDataSize(&idec->mem_);
|
2012-04-05 11:31:10 +02:00
|
|
|
assert(idec->is_lossless_);
|
2012-04-11 03:41:18 +02:00
|
|
|
|
|
|
|
// At present Lossless decoder can't decode image incrementally. So wait till
|
|
|
|
// all the image data is aggregated before image can be decoded.
|
2012-04-05 11:31:10 +02:00
|
|
|
if (curr_size < idec->chunk_size_) {
|
2012-04-11 03:41:18 +02:00
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
if (!VP8LDecodeImage(dec)) {
|
|
|
|
return ErrorStatusLossless(idec, dec->status_);
|
2012-04-11 03:41:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
idec->state_ = STATE_DONE;
|
|
|
|
|
|
|
|
return VP8_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-24 02:03:53 +01:00
|
|
|
// Main decoding loop
|
|
|
|
static VP8StatusCode IDecode(WebPIDecoder* idec) {
|
|
|
|
VP8StatusCode status = VP8_STATUS_SUSPENDED;
|
|
|
|
|
2011-09-13 11:35:10 +02:00
|
|
|
if (idec->state_ == STATE_PRE_VP8) {
|
|
|
|
status = DecodeWebPHeaders(idec);
|
2012-04-05 11:31:10 +02:00
|
|
|
} else {
|
|
|
|
if (idec->dec_ == NULL) {
|
|
|
|
return VP8_STATUS_SUSPENDED; // can't continue if we have no decoder.
|
|
|
|
}
|
2011-09-13 11:35:10 +02:00
|
|
|
}
|
|
|
|
if (idec->state_ == STATE_VP8_FRAME_HEADER) {
|
|
|
|
status = DecodeVP8FrameHeader(idec);
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
2011-09-13 11:35:10 +02:00
|
|
|
if (idec->state_ == STATE_VP8_PARTS0) {
|
2011-03-24 02:03:53 +01:00
|
|
|
status = DecodePartition0(idec);
|
|
|
|
}
|
2011-09-13 11:35:10 +02:00
|
|
|
if (idec->state_ == STATE_VP8_DATA) {
|
2011-06-20 09:45:15 +02:00
|
|
|
status = DecodeRemaining(idec);
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
2012-04-11 03:41:18 +02:00
|
|
|
if (idec->state_ == STATE_VP8L_HEADER) {
|
|
|
|
status = DecodeVP8LHeader(idec);
|
|
|
|
}
|
|
|
|
if (idec->state_ == STATE_VP8L_DATA) {
|
|
|
|
status = DecodeVP8LData(idec);
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Public functions
|
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
WebPIDecoder* WebPINewDecoder(WebPDecBuffer* const output_buffer) {
|
2011-03-24 02:03:53 +01:00
|
|
|
WebPIDecoder* idec = (WebPIDecoder*)calloc(1, sizeof(WebPIDecoder));
|
2011-06-20 09:45:15 +02:00
|
|
|
if (idec == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
|
2011-09-13 11:35:10 +02:00
|
|
|
idec->state_ = STATE_PRE_VP8;
|
2012-04-05 11:31:10 +02:00
|
|
|
idec->chunk_size_ = 0;
|
2011-05-20 04:07:01 +02:00
|
|
|
|
2011-03-24 02:03:53 +01:00
|
|
|
InitMemBuffer(&idec->mem_);
|
2011-06-20 09:45:15 +02:00
|
|
|
WebPInitDecBuffer(&idec->output_);
|
2011-03-24 02:03:53 +01:00
|
|
|
VP8InitIo(&idec->io_);
|
2011-06-20 09:45:15 +02:00
|
|
|
|
|
|
|
WebPResetDecParams(&idec->params_);
|
|
|
|
idec->params_.output = output_buffer ? output_buffer : &idec->output_;
|
|
|
|
WebPInitCustomIo(&idec->params_, &idec->io_); // Plug the I/O functions.
|
|
|
|
|
|
|
|
return idec;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebPIDecoder* WebPIDecode(const uint8_t* data, uint32_t data_size,
|
|
|
|
WebPDecoderConfig* const config) {
|
|
|
|
WebPIDecoder* idec;
|
|
|
|
|
|
|
|
// Parse the bitstream's features, if requested:
|
|
|
|
if (data != NULL && data_size > 0 && config != NULL) {
|
|
|
|
if (WebPGetFeatures(data, data_size, &config->input) != VP8_STATUS_OK) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Create an instance of the incremental decoder
|
|
|
|
idec = WebPINewDecoder(config ? &config->output : NULL);
|
|
|
|
if (!idec) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Finish initialization
|
|
|
|
if (config != NULL) {
|
|
|
|
idec->params_.options = &config->options;
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
return idec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebPIDelete(WebPIDecoder* const idec) {
|
2012-04-05 11:31:10 +02:00
|
|
|
if (idec == NULL) return;
|
|
|
|
if (idec->dec_ != NULL) {
|
|
|
|
if (!idec->is_lossless_) {
|
|
|
|
VP8Delete(idec->dec_);
|
|
|
|
} else {
|
|
|
|
VP8LDelete(idec->dec_);
|
|
|
|
}
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
ClearMemBuffer(&idec->mem_);
|
2011-06-20 09:45:15 +02:00
|
|
|
WebPFreeDecBuffer(&idec->output_);
|
2011-03-24 02:03:53 +01:00
|
|
|
free(idec);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2011-06-20 09:45:15 +02:00
|
|
|
// Wrapper toward WebPINewDecoder
|
|
|
|
|
|
|
|
WebPIDecoder* WebPINew(WEBP_CSP_MODE mode) {
|
|
|
|
WebPIDecoder* const idec = WebPINewDecoder(NULL);
|
|
|
|
if (!idec) return NULL;
|
|
|
|
idec->output_.colorspace = mode;
|
|
|
|
return idec;
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
|
|
|
|
WebPIDecoder* WebPINewRGB(WEBP_CSP_MODE mode, uint8_t* output_buffer,
|
|
|
|
int output_buffer_size, int output_stride) {
|
|
|
|
WebPIDecoder* idec;
|
2011-06-20 09:45:15 +02:00
|
|
|
if (mode >= MODE_YUV) return NULL;
|
|
|
|
idec = WebPINewDecoder(NULL);
|
|
|
|
if (!idec) return NULL;
|
|
|
|
idec->output_.colorspace = mode;
|
|
|
|
idec->output_.is_external_memory = 1;
|
|
|
|
idec->output_.u.RGBA.rgba = output_buffer;
|
|
|
|
idec->output_.u.RGBA.stride = output_stride;
|
|
|
|
idec->output_.u.RGBA.size = output_buffer_size;
|
2011-03-24 02:03:53 +01:00
|
|
|
return idec;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebPIDecoder* WebPINewYUV(uint8_t* luma, int luma_size, int luma_stride,
|
|
|
|
uint8_t* u, int u_size, int u_stride,
|
|
|
|
uint8_t* v, int v_size, int v_stride) {
|
2011-06-20 09:45:15 +02:00
|
|
|
WebPIDecoder* const idec = WebPINewDecoder(NULL);
|
|
|
|
if (!idec) return NULL;
|
|
|
|
idec->output_.colorspace = MODE_YUV;
|
|
|
|
idec->output_.is_external_memory = 1;
|
|
|
|
idec->output_.u.YUVA.y = luma;
|
|
|
|
idec->output_.u.YUVA.y_stride = luma_stride;
|
|
|
|
idec->output_.u.YUVA.y_size = luma_size;
|
|
|
|
idec->output_.u.YUVA.u = u;
|
|
|
|
idec->output_.u.YUVA.u_stride = u_stride;
|
|
|
|
idec->output_.u.YUVA.u_size = u_size;
|
|
|
|
idec->output_.u.YUVA.v = v;
|
|
|
|
idec->output_.u.YUVA.v_stride = v_stride;
|
|
|
|
idec->output_.u.YUVA.v_size = v_size;
|
2011-03-24 02:03:53 +01:00
|
|
|
return idec;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static VP8StatusCode IDecCheckStatus(const WebPIDecoder* const idec) {
|
|
|
|
assert(idec);
|
|
|
|
if (idec->state_ == STATE_ERROR) {
|
|
|
|
return VP8_STATUS_BITSTREAM_ERROR;
|
|
|
|
}
|
|
|
|
if (idec->state_ == STATE_DONE) {
|
|
|
|
return VP8_STATUS_OK;
|
|
|
|
}
|
|
|
|
return VP8_STATUS_SUSPENDED;
|
|
|
|
}
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8StatusCode WebPIAppend(WebPIDecoder* const idec,
|
|
|
|
const uint8_t* const data, uint32_t data_size) {
|
2011-03-25 23:04:11 +01:00
|
|
|
VP8StatusCode status;
|
2011-03-24 02:03:53 +01:00
|
|
|
if (idec == NULL || data == NULL) {
|
|
|
|
return VP8_STATUS_INVALID_PARAM;
|
|
|
|
}
|
2011-03-25 23:04:11 +01:00
|
|
|
status = IDecCheckStatus(idec);
|
2011-03-24 02:03:53 +01:00
|
|
|
if (status != VP8_STATUS_SUSPENDED) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
|
|
|
|
if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_APPEND)) {
|
|
|
|
return VP8_STATUS_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
// Append data to memory buffer
|
|
|
|
if (!AppendToMemBuffer(idec, data, data_size)) {
|
|
|
|
return VP8_STATUS_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return IDecode(idec);
|
|
|
|
}
|
|
|
|
|
2012-04-05 11:31:10 +02:00
|
|
|
VP8StatusCode WebPIUpdate(WebPIDecoder* const idec,
|
|
|
|
const uint8_t* const data, uint32_t data_size) {
|
2011-03-25 23:04:11 +01:00
|
|
|
VP8StatusCode status;
|
2011-03-24 02:03:53 +01:00
|
|
|
if (idec == NULL || data == NULL) {
|
|
|
|
return VP8_STATUS_INVALID_PARAM;
|
|
|
|
}
|
2011-03-25 23:04:11 +01:00
|
|
|
status = IDecCheckStatus(idec);
|
2011-03-24 02:03:53 +01:00
|
|
|
if (status != VP8_STATUS_SUSPENDED) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
// Check mixed calls between RemapMemBuffer and AppendToMemBuffer.
|
|
|
|
if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_MAP)) {
|
|
|
|
return VP8_STATUS_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
// Make the memory buffer point to the new buffer
|
|
|
|
if (!RemapMemBuffer(idec, data, data_size)) {
|
|
|
|
return VP8_STATUS_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
return IDecode(idec);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
static const WebPDecBuffer* GetOutputBuffer(const WebPIDecoder* const idec) {
|
2012-04-05 11:31:10 +02:00
|
|
|
if (idec == NULL || idec->dec_ == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (idec->state_ <= STATE_VP8_PARTS0) {
|
2011-03-24 02:03:53 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-20 09:45:15 +02:00
|
|
|
return idec->params_.output;
|
|
|
|
}
|
2011-03-24 02:03:53 +01:00
|
|
|
|
2011-07-12 22:59:51 +02:00
|
|
|
const WebPDecBuffer* WebPIDecodedArea(const WebPIDecoder* const idec,
|
|
|
|
int* const left, int* const top,
|
|
|
|
int* const width, int* const height) {
|
2011-06-20 09:45:15 +02:00
|
|
|
const WebPDecBuffer* const src = GetOutputBuffer(idec);
|
2011-07-12 22:59:51 +02:00
|
|
|
if (left) *left = 0;
|
|
|
|
if (top) *top = 0;
|
|
|
|
// TODO(skal): later include handling of rotations.
|
|
|
|
if (src) {
|
|
|
|
if (width) *width = src->width;
|
|
|
|
if (height) *height = idec->params_.last_y;
|
|
|
|
} else {
|
|
|
|
if (width) *width = 0;
|
|
|
|
if (height) *height = 0;
|
|
|
|
}
|
2011-06-20 09:45:15 +02:00
|
|
|
return src;
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
uint8_t* WebPIDecGetRGB(const WebPIDecoder* const idec, int* last_y,
|
|
|
|
int* width, int* height, int* stride) {
|
|
|
|
const WebPDecBuffer* const src = GetOutputBuffer(idec);
|
|
|
|
if (!src) return NULL;
|
|
|
|
if (src->colorspace >= MODE_YUV) {
|
2011-03-24 02:03:53 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_y) *last_y = idec->params_.last_y;
|
2011-06-20 09:45:15 +02:00
|
|
|
if (width) *width = src->width;
|
|
|
|
if (height) *height = src->height;
|
|
|
|
if (stride) *stride = src->u.RGBA.stride;
|
2011-03-24 02:03:53 +01:00
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
return src->u.RGBA.rgba;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* WebPIDecGetYUV(const WebPIDecoder* const idec, int* last_y,
|
|
|
|
uint8_t** u, uint8_t** v,
|
|
|
|
int* width, int* height, int *stride, int* uv_stride) {
|
|
|
|
const WebPDecBuffer* const src = GetOutputBuffer(idec);
|
|
|
|
if (!src) return NULL;
|
|
|
|
if (src->colorspace < MODE_YUV) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_y) *last_y = idec->params_.last_y;
|
|
|
|
if (u) *u = src->u.YUVA.u;
|
|
|
|
if (v) *v = src->u.YUVA.v;
|
|
|
|
if (width) *width = src->width;
|
|
|
|
if (height) *height = src->height;
|
|
|
|
if (stride) *stride = src->u.YUVA.y_stride;
|
|
|
|
if (uv_stride) *uv_stride = src->u.YUVA.u_stride;
|
|
|
|
|
|
|
|
return src->u.YUVA.y;
|
2011-03-24 02:03:53 +01:00
|
|
|
}
|
2011-03-24 02:41:18 +01:00
|
|
|
|
2011-07-08 01:38:03 +02:00
|
|
|
int WebPISetIOHooks(WebPIDecoder* const idec,
|
|
|
|
VP8IoPutHook put,
|
|
|
|
VP8IoSetupHook setup,
|
|
|
|
VP8IoTeardownHook teardown,
|
|
|
|
void* user_data) {
|
2012-04-05 11:31:10 +02:00
|
|
|
if (idec == NULL || idec->state_ > STATE_PRE_VP8) {
|
2011-07-08 01:38:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
idec->io_.put = put;
|
|
|
|
idec->io_.setup = setup;
|
|
|
|
idec->io_.teardown = teardown;
|
|
|
|
idec->io_.opaque = user_data;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-03-24 02:41:18 +01:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|