Lines Matching defs:mem
96 static WEBP_INLINE size_t MemDataSize(const MemBuffer* mem) {
97 return (mem->end_ - mem->start_);
101 MemBuffer* const mem = &idec->mem_;
102 const uint8_t* const new_base = mem->buf_ + mem->start_;
106 idec->io_.data_size = MemDataSize(mem);
119 if (mem->mode_ == MEM_MODE_MAP) {
124 dec->parts_[last_part].buf_end_ = mem->buf_ + mem->end_;
127 VP8LBitReaderSetBuffer(&dec->br_, new_base, MemDataSize(mem));
136 MemBuffer* const mem = &idec->mem_;
137 const uint8_t* const old_base = mem->buf_ + mem->start_;
138 assert(mem->mode_ == MEM_MODE_APPEND);
145 if (mem->end_ + data_size > mem->buf_size_) { // Need some free memory
146 const size_t current_size = MemDataSize(mem);
153 free(mem->buf_);
154 mem->buf_ = new_buf;
155 mem->buf_size_ = (size_t)extra_size;
156 mem->start_ = 0;
157 mem->end_ = current_size;
160 memcpy(mem->buf_ + mem->end_, data, data_size);
161 mem->end_ += data_size;
162 assert(mem->end_ <= mem->buf_size_);
164 DoRemap(idec, mem->buf_ + mem->start_ - old_base);
170 MemBuffer* const mem = &idec->mem_;
171 const uint8_t* const old_base = mem->buf_ + mem->start_;
172 assert(mem->mode_ == MEM_MODE_MAP);
174 if (data_size < mem->buf_size_) return 0; // can't remap to a shorter buffer!
176 mem->buf_ = (uint8_t*)data;
177 mem->end_ = mem->buf_size_ = data_size;
179 DoRemap(idec, mem->buf_ + mem->start_ - old_base);
183 static void InitMemBuffer(MemBuffer* const mem) {
184 mem->mode_ = MEM_MODE_NONE;
185 mem->buf_ = NULL;
186 mem->buf_size_ = 0;
187 mem->part0_buf_ = NULL;
188 mem->part0_size_ = 0;
191 static void ClearMemBuffer(MemBuffer* const mem) {
192 assert(mem);
193 if (mem->mode_ == MEM_MODE_APPEND) {
194 free(mem->buf_);
195 free((void*)mem->part0_buf_);
199 static int CheckMemBufferMode(MemBuffer* const mem, MemBufferMode expected) {
200 if (mem->mode_ == MEM_MODE_NONE) {
201 mem->mode_ = expected; // switch to the expected mode
202 } else if (mem->mode_ != expected) {
205 assert(mem->mode_ == expected); // mode is ok
255 MemBuffer* const mem = &idec->mem_;
257 mem->start_ += consumed_bytes;
258 assert(mem->start_ <= mem->end_);
259 idec->io_.data = mem->buf_ + mem->start_;
260 idec->io_.data_size = MemDataSize(mem);
265 MemBuffer* const mem = &idec->mem_;
266 const uint8_t* data = mem->buf_ + mem->start_;
267 size_t curr_size = MemDataSize(mem);
335 MemBuffer* const mem = &idec->mem_;
337 assert(mem->part0_buf_ == NULL);
339 assert(psize <= mem->part0_size_); // Format limit: no need for runtime check
340 if (mem->mode_ == MEM_MODE_APPEND) {
347 mem->part0_buf_ = part0_buf;
353 mem->start_ += psize;