coda-h264.c 1014 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Coda multi-standard codec IP - H.264 helper functions
  3. *
  4. * Copyright (C) 2012 Vista Silicon S.L.
  5. * Javier Martin, <javier.martin@vista-silicon.com>
  6. * Xavier Duret
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/string.h>
  15. #include <coda.h>
  16. static const u8 coda_filler_nal[14] = { 0x00, 0x00, 0x00, 0x01, 0x0c, 0xff,
  17. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 };
  18. static const u8 coda_filler_size[8] = { 0, 7, 14, 13, 12, 11, 10, 9 };
  19. int coda_h264_padding(int size, char *p)
  20. {
  21. int nal_size;
  22. int diff;
  23. diff = size - (size & ~0x7);
  24. if (diff == 0)
  25. return 0;
  26. nal_size = coda_filler_size[diff];
  27. memcpy(p, coda_filler_nal, nal_size);
  28. /* Add rbsp stop bit and trailing at the end */
  29. *(p + nal_size - 1) = 0x80;
  30. return nal_size;
  31. }