| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Paginated token buffer | 10 // Paginated token buffer |
| 11 // | 11 // |
| 12 // A 'token' is a bit value associated with a probability, either fixed | 12 // A 'token' is a bit value associated with a probability, either fixed |
| 13 // or a later-to-be-determined after statistics have been collected. | 13 // or a later-to-be-determined after statistics have been collected. |
| 14 // For dynamic probability, we just record the slot id (idx) for the probability | 14 // For dynamic probability, we just record the slot id (idx) for the probability |
| 15 // value in the final probability array (uint8_t* probas in VP8EmitTokens). | 15 // value in the final probability array (uint8_t* probas in VP8EmitTokens). |
| 16 // | 16 // |
| 17 // Author: Skal (pascal.massimino@gmail.com) | 17 // Author: Skal (pascal.massimino@gmail.com) |
| 18 | 18 |
| 19 #include <assert.h> | 19 #include <assert.h> |
| 20 #include <stdlib.h> | 20 #include <stdlib.h> |
| 21 #include <string.h> | 21 #include <string.h> |
| 22 | 22 |
| 23 #include "./cost.h" |
| 23 #include "./vp8enci.h" | 24 #include "./vp8enci.h" |
| 24 | 25 |
| 25 #if defined(__cplusplus) || defined(c_plusplus) | |
| 26 extern "C" { | |
| 27 #endif | |
| 28 | |
| 29 #if !defined(DISABLE_TOKEN_BUFFER) | 26 #if !defined(DISABLE_TOKEN_BUFFER) |
| 30 | 27 |
| 31 // we use pages to reduce the number of memcpy() | 28 // we use pages to reduce the number of memcpy() |
| 32 #define MAX_NUM_TOKEN 8192 // max number of token per page | 29 #define MAX_NUM_TOKEN 8192 // max number of token per page |
| 33 #define FIXED_PROBA_BIT (1u << 14) | 30 #define FIXED_PROBA_BIT (1u << 14) |
| 34 | 31 |
| 35 struct VP8Tokens { | 32 struct VP8Tokens { |
| 36 uint16_t tokens_[MAX_NUM_TOKEN]; // bit#15: bit | 33 uint16_t tokens_[MAX_NUM_TOKEN]; // bit#15: bit |
| 37 // bit #14: constant proba or idx | 34 // bit #14: constant proba or idx |
| 38 // bits 0..13: slot or constant proba | 35 // bits 0..13: slot or constant proba |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 VP8PutBit(bw, bit, probas[token & 0x3fffu]); | 228 VP8PutBit(bw, bit, probas[token & 0x3fffu]); |
| 232 } | 229 } |
| 233 } | 230 } |
| 234 if (final_pass) free((void*)p); | 231 if (final_pass) free((void*)p); |
| 235 p = next; | 232 p = next; |
| 236 } | 233 } |
| 237 if (final_pass) b->pages_ = NULL; | 234 if (final_pass) b->pages_ = NULL; |
| 238 return 1; | 235 return 1; |
| 239 } | 236 } |
| 240 | 237 |
| 238 // Size estimation |
| 239 size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas) { |
| 240 size_t size = 0; |
| 241 const VP8Tokens* p = b->pages_; |
| 242 if (b->error_) return 0; |
| 243 while (p != NULL) { |
| 244 const VP8Tokens* const next = p->next_; |
| 245 const int N = (next == NULL) ? b->left_ : 0; |
| 246 int n = MAX_NUM_TOKEN; |
| 247 while (n-- > N) { |
| 248 const uint16_t token = p->tokens_[n]; |
| 249 const int bit = token & (1 << 15); |
| 250 if (token & FIXED_PROBA_BIT) { |
| 251 size += VP8BitCost(bit, token & 0xffu); |
| 252 } else { |
| 253 size += VP8BitCost(bit, probas[token & 0x3fffu]); |
| 254 } |
| 255 } |
| 256 p = next; |
| 257 } |
| 258 return size; |
| 259 } |
| 260 |
| 241 //------------------------------------------------------------------------------ | 261 //------------------------------------------------------------------------------ |
| 242 | 262 |
| 243 #else // DISABLE_TOKEN_BUFFER | 263 #else // DISABLE_TOKEN_BUFFER |
| 244 | 264 |
| 245 void VP8TBufferInit(VP8TBuffer* const b) { | 265 void VP8TBufferInit(VP8TBuffer* const b) { |
| 246 (void)b; | 266 (void)b; |
| 247 } | 267 } |
| 248 void VP8TBufferClear(VP8TBuffer* const b) { | 268 void VP8TBufferClear(VP8TBuffer* const b) { |
| 249 (void)b; | 269 (void)b; |
| 250 } | 270 } |
| 251 | 271 |
| 252 #endif // !DISABLE_TOKEN_BUFFER | 272 #endif // !DISABLE_TOKEN_BUFFER |
| 253 | 273 |
| 254 #if defined(__cplusplus) || defined(c_plusplus) | |
| 255 } // extern "C" | |
| 256 #endif | |
| OLD | NEW |