offset_type BlockManager::AllocExistBlock() { CheckHeader(); assert(m_Header.Unused.offset >= 0); offset_type result = m_Header.Unused; offset_type header; ReadEmptyBlockHeader(result, header); m_Header.Unused = header; header = result; ZeroBlock(result); FlushHeader(); return result; }
/*------------------------------------------------------------------------------ EncInter Encodes one INTER macroblock using plain MPEG-4 stream syntax ------------------------------------------------------------------------------*/ void EncInter(stream_s *stream, mb_s *mb) { /* Zero block check, inter DC is coded together with AC-components */ ZeroBlock(mb->zeroBlock, mb->rlcCount, NULL, ENCHW_NO); mb->notCoded = NotCodedMb(&mb->mv[mb->mbNum], mb->zeroBlock); EncMbHeader(stream, mb); EncVlcInter(stream, mb); return; }
/*------------------------------------------------------------------------------ EncInterDp Encodes one INTER macroblock using data partitioned stream syntax ------------------------------------------------------------------------------*/ void EncInterDp(stream_s *stream, stream_s *stream1, stream_s *stream2, mb_s *mb) { /* Zero block check, inter DC is coded together with AC-components */ ZeroBlock(mb->zeroBlock, mb->rlcCount, NULL, ENCHW_NO); mb->notCoded = NotCodedMb(&mb->mv[mb->mbNum], mb->zeroBlock); EncMbHeaderInterDp(stream, stream1, mb, ENCHW_NO); if (mb->rvlc == ENCHW_YES) { EncRvlcInter(stream2, mb); } else { EncVlcInter(stream2, mb); } return; }
/*------------------------------------------------------------------------------ EncIntra Encodes one INTRA macroblock using plain MPEG-4 stream syntax ------------------------------------------------------------------------------*/ void EncIntra(stream_s *stream, mb_s *mb) { true_e dcSeparately; /* Dc prediction */ EncPrediction(mb); /* Separately coded DC-coeff and zero block decision */ dcSeparately = IntraDcDecision(mb->qpLastCoded, mb->qp, mb->intraDcVlcThr); ZeroBlock(mb->zeroBlock, mb->rlcCount, mb->dc, dcSeparately); EncMbHeader(stream, mb); if (dcSeparately == ENCHW_YES) { EncVlcIntra(stream, mb, DC_VLC_INTRA_DC); } else { EncVlcIntra(stream, mb, DC_VLC_INTRA_AC); } return; }
/*------------------------------------------------------------------------------ EncIntraDp Encodes one INTRA macroblock using data partitioned stream syntax ------------------------------------------------------------------------------*/ void EncIntraDp(stream_s *stream, stream_s *stream1, stream_s *stream2, mb_s *mb) { true_e dcSeparately; dcVlc_e dcCodingType; /* Dc prediction */ EncPrediction(mb); /* Separately coded DC-coeff and zero block decision */ dcSeparately = IntraDcDecision(mb->qpLastCoded, mb->qp, mb->intraDcVlcThr); ZeroBlock(mb->zeroBlock, mb->rlcCount, mb->dc, dcSeparately); /* Macroblock header is different for IVOP intra mb and PVOP intra mb */ if (mb->vopType == IVOP) { EncMbHeaderIntraDp(stream, stream1, mb, dcSeparately); } else { EncMbHeaderInterDp(stream, stream1, mb, dcSeparately); } /* Separately coded Intra DC-coeffs are coded in MB header */ if (dcSeparately == ENCHW_YES) dcCodingType = DC_VLC_NO; else dcCodingType = DC_VLC_INTRA_AC; if (mb->rvlc == ENCHW_YES) { EncRvlcIntra(stream2, mb, dcCodingType); } else { EncVlcIntra(stream2, mb, dcCodingType); } return; }
CPLErr GDALWMSRasterBand::ReadBlocks(int x, int y, void *buffer, int bx0, int by0, int bx1, int by1, int advise_read) { CPLErr ret = CE_None; int i; int max_request_count = (bx1 - bx0 + 1) * (by1 - by0 + 1); int request_count = 0; CPLHTTPRequest *download_requests = NULL; GDALWMSCache *cache = m_parent_dataset->m_cache; struct BlockXY { int x, y; } *download_blocks = NULL; if (!m_parent_dataset->m_offline_mode) { download_requests = new CPLHTTPRequest[max_request_count]; download_blocks = new BlockXY[max_request_count]; } char **http_request_opts = NULL; if (m_parent_dataset->m_http_timeout != -1) { CPLString http_request_optstr; http_request_optstr.Printf("TIMEOUT=%d", m_parent_dataset->m_http_timeout); http_request_opts = CSLAddString(http_request_opts, http_request_optstr.c_str()); } for (int iy = by0; iy <= by1; ++iy) { for (int ix = bx0; ix <= bx1; ++ix) { bool need_this_block = false; if (!advise_read) { for (int ib = 1; ib <= m_parent_dataset->nBands; ++ib) { if ((ix == x) && (iy == y) && (ib == nBand)) { need_this_block = true; } else { GDALWMSRasterBand *band = static_cast<GDALWMSRasterBand *>(m_parent_dataset->GetRasterBand(ib)); if (m_overview >= 0) band = static_cast<GDALWMSRasterBand *>(band->GetOverview(m_overview)); if (!band->IsBlockInCache(ix, iy)) need_this_block = true; } } } else { need_this_block = true; } CPLString url; if (need_this_block) { CPLString file_name; AskMiniDriverForBlock(&url, ix, iy); if ((cache != NULL) && (cache->Read(url.c_str(), &file_name) == CE_None)) { if (advise_read) { need_this_block = false; } else { void *p = 0; if ((ix == x) && (iy == y)) p = buffer; if (ReadBlockFromFile(ix, iy, file_name.c_str(), nBand, p, 0) == CE_None) need_this_block = false; } } } if (need_this_block) { if (m_parent_dataset->m_offline_mode) { if (!advise_read) { void *p = 0; if ((ix == x) && (iy == y)) p = buffer; if (ZeroBlock(ix, iy, nBand, p) != CE_None) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: ZeroBlock failed."); ret = CE_Failure; } } } else { CPLHTTPInitializeRequest(&download_requests[request_count], url.c_str(), http_request_opts); download_blocks[request_count].x = ix; download_blocks[request_count].y = iy; ++request_count; } } } } if (http_request_opts != NULL) { CSLDestroy(http_request_opts); } if (request_count > 0) { char **opts = NULL; CPLString optstr; if (m_parent_dataset->m_http_max_conn != -1) { optstr.Printf("MAXCONN=%d", m_parent_dataset->m_http_max_conn); opts = CSLAddString(opts, optstr.c_str()); } if (CPLHTTPFetchMulti(download_requests, request_count, opts) != CE_None) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: CPLHTTPFetchMulti failed."); ret = CE_Failure; } if (opts != NULL) { CSLDestroy(opts); } } for (i = 0; i < request_count; ++i) { if (ret == CE_None) { if ((download_requests[i].nStatus == 200) && (download_requests[i].pabyData != NULL) && (download_requests[i].nDataLen > 0)) { CPLString file_name(BufferToVSIFile(download_requests[i].pabyData, download_requests[i].nDataLen)); if (file_name.size() > 0) { /* check for error xml */ if (download_requests[i].nDataLen >= 20) { const char *download_data = reinterpret_cast<char *>(download_requests[i].pabyData); if (EQUALN(download_data, "<?xml ", 6) || EQUALN(download_data, "<!DOCTYPE ", 10) || EQUALN(download_data, "<ServiceException", 17)) { if (ReportWMSException(file_name.c_str()) != CE_None) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: The server returned unknown exception."); } ret = CE_Failure; } } if (ret == CE_None) { if (advise_read && !m_parent_dataset->m_verify_advise_read) { if (cache != NULL) { cache->Write(download_requests[i].pszURL, file_name); } } else { void *p = 0; if ((download_blocks[i].x == x) && (download_blocks[i].y == y)) p = buffer; if (ReadBlockFromFile(download_blocks[i].x, download_blocks[i].y, file_name.c_str(), nBand, p, advise_read) == CE_None) { if (cache != NULL) { cache->Write(download_requests[i].pszURL, file_name); } } else { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: ReadBlockFromFile (%s) failed.", download_requests[i].pszURL); ret = CE_Failure; } } } VSIUnlink(file_name.c_str()); } } else if (download_requests[i].nStatus == 204) { if (!advise_read) { void *p = 0; if ((download_blocks[i].x == x) && (download_blocks[i].y == y)) p = buffer; if (ZeroBlock(download_blocks[i].x, download_blocks[i].y, nBand, p) != CE_None) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: ZeroBlock failed."); ret = CE_Failure; } } } else { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: Unable to download block %d, %d.\n URL: %s\n HTTP status code: %d, error: %s.", download_blocks[i].x, download_blocks[i].y, download_requests[i].pszURL, download_requests[i].nStatus, download_requests[i].pszError ? download_requests[i].pszError : "(null)"); ret = CE_Failure; } } CPLHTTPCleanupRequest(&download_requests[i]); } if (!m_parent_dataset->m_offline_mode) { delete[] download_blocks; delete[] download_requests; } return ret; }