Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.9 KiB

  1. #include <win32.h>
  2. #include <vfw.h>
  3. #include "extra.h"
  4. #include "debug.h"
  5. #ifndef HPBYTE
  6. #define HPBYTE BYTE huge *
  7. #endif
  8. HRESULT ReadExtra(LPEXTRA extra,
  9. DWORD ckid,
  10. LPVOID lpData,
  11. LONG FAR *lpcbData)
  12. {
  13. #define lpdw ((DWORD UNALIGNED HUGE *) lp)
  14. HPBYTE lp = (HPBYTE) extra->lp;
  15. LONG cb = extra->cb;
  16. LONG cbData;
  17. while (cb >= 2 * sizeof(DWORD)) {
  18. cbData = (LONG) lpdw[1];
  19. if (lpdw[0] == ckid) {
  20. if (lpData) {
  21. hmemcpy(lpData, lp + 2 * sizeof(DWORD), min(cbData, *lpcbData));
  22. }
  23. *lpcbData = cbData;
  24. return ResultFromScode(AVIERR_OK);
  25. }
  26. if (cbData & 1)
  27. cbData++;
  28. cb -= cbData + sizeof(DWORD) * 2;
  29. lp += cbData + sizeof(DWORD) * 2;
  30. }
  31. #undef lpdw
  32. *lpcbData = 0;
  33. return ResultFromScode(AVIERR_NODATA);
  34. }
  35. HRESULT WriteExtra(LPEXTRA extra,
  36. DWORD ckid,
  37. LPVOID lpData,
  38. LONG cbData)
  39. {
  40. HPBYTE lp;
  41. cbData += sizeof(DWORD) * 2;
  42. if (extra->lp) {
  43. lp = (HPBYTE) GlobalReAllocPtr(extra->lp, extra->cb + cbData, GMEM_MOVEABLE | GMEM_SHARE);
  44. DPF("Extra cb is now %ld\n", extra->cb + cbData);
  45. } else {
  46. lp = (HPBYTE) GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE, cbData);
  47. }
  48. if (!lp) {
  49. return ResultFromScode(AVIERR_MEMORY);
  50. }
  51. // !!! Should go and get rid of other chunks with same type!
  52. // build RIFF chunk in block
  53. ((DWORD UNALIGNED HUGE *) (lp + extra->cb))[0] = ckid;
  54. ((DWORD UNALIGNED HUGE *) (lp + extra->cb))[1] = cbData - sizeof(DWORD) * 2;
  55. hmemcpy(lp + extra->cb + sizeof(DWORD) * 2,
  56. lpData,
  57. cbData - sizeof(DWORD) * 2);
  58. if (cbData & 1)
  59. cbData++;
  60. extra->lp = lp;
  61. extra->cb += cbData;
  62. return ResultFromScode(AVIERR_OK);
  63. }
  64. HRESULT ReadIntoExtra(LPEXTRA extra,
  65. HSHFILE hshfile,
  66. MMCKINFO FAR * lpck)
  67. {
  68. HPBYTE lp;
  69. LONG cbData = lpck->cksize + sizeof(DWORD) * 2;
  70. DPF("ReadIntoExtra: now %ld bytes.\n", extra->cb + cbData);
  71. if (extra->lp) {
  72. lp = (HPBYTE) GlobalReAllocPtr(extra->lp, extra->cb + cbData, GMEM_MOVEABLE | GMEM_SHARE);
  73. } else {
  74. lp = (HPBYTE) GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE, cbData);
  75. }
  76. if (!lp)
  77. return ResultFromScode(AVIERR_MEMORY);
  78. extra->lp = lp;
  79. // build RIFF chunk in block
  80. ((DWORD UNALIGNED HUGE *) (lp + extra->cb))[0] = lpck->ckid;
  81. ((DWORD UNALIGNED HUGE *) (lp + extra->cb))[1] = lpck->cksize;
  82. cbData += (cbData & 1);
  83. shfileSeek(hshfile, lpck->dwDataOffset, SEEK_SET);
  84. if (shfileRead(hshfile, (HPSTR) lp + extra->cb + sizeof(DWORD) * 2, lpck->cksize) !=
  85. (LONG) lpck->cksize)
  86. return ResultFromScode(AVIERR_FILEREAD);
  87. extra->cb += cbData;
  88. return ResultFromScode(AVIERR_OK);
  89. }
  90. LONG FindChunkAndKeepExtras(LPEXTRA extra, HSHFILE hshfile,
  91. MMCKINFO FAR* lpck, MMCKINFO FAR* lpckParent,
  92. UINT uFlags)
  93. {
  94. FOURCC ckidFind; // chunk ID to find (or NULL)
  95. FOURCC fccTypeFind; // form/list type to find (or NULL)
  96. LONG lRet;
  97. /* figure out what chunk id and form/list type to search for */
  98. if (uFlags & MMIO_FINDCHUNK)
  99. ckidFind = lpck->ckid, fccTypeFind = NULL;
  100. else if (uFlags & MMIO_FINDRIFF)
  101. ckidFind = FOURCC_RIFF, fccTypeFind = lpck->fccType;
  102. else if (uFlags & MMIO_FINDLIST)
  103. ckidFind = FOURCC_LIST, fccTypeFind = lpck->fccType;
  104. else
  105. ckidFind = fccTypeFind = (FOURCC) -1; // keep looking indefinitely
  106. for (;;) {
  107. lRet = shfileDescend(hshfile, lpck, lpckParent, 0);
  108. if (lRet) {
  109. if (uFlags == 0 && lRet == MMIOERR_CHUNKNOTFOUND)
  110. lRet = 0;
  111. return lRet;
  112. }
  113. if ((!ckidFind || lpck->ckid == ckidFind) &&
  114. (!fccTypeFind || lpck->fccType == fccTypeFind))
  115. return 0;
  116. if (lpck->ckid != mmioFOURCC('J', 'U', 'N', 'K')) {
  117. lRet = (LONG) ReadIntoExtra(extra, hshfile, lpck);
  118. if (lRet != AVIERR_OK)
  119. return lRet;
  120. }
  121. shfileAscend(hshfile, lpck, 0);
  122. }
  123. }