nsresult nsSHistory::CompareFrames(nsISHEntry * aPrevEntry, nsISHEntry * aNextEntry, nsIDocShell * aParent, long aLoadType, PRBool * aIsFrameFound) { if (!aPrevEntry || !aNextEntry || !aParent) return PR_FALSE; nsresult result = NS_OK; PRUint32 prevID, nextID; aPrevEntry->GetID(&prevID); aNextEntry->GetID(&nextID); // Check the IDs to verify if the pages are different. if (prevID != nextID) { if (aIsFrameFound) *aIsFrameFound = PR_TRUE; // Set the Subframe flag of the entry to indicate that // it is subframe navigation aNextEntry->SetIsSubFrame(PR_TRUE); InitiateLoad(aNextEntry, aParent, aLoadType); return NS_OK; } /* The root entries are the same, so compare any child frames */ PRInt32 pcnt=0, ncnt=0, dsCount=0; nsCOMPtr<nsISHContainer> prevContainer(do_QueryInterface(aPrevEntry)); nsCOMPtr<nsISHContainer> nextContainer(do_QueryInterface(aNextEntry)); nsCOMPtr<nsIDocShellTreeNode> dsTreeNode(do_QueryInterface(aParent)); if (!dsTreeNode) return NS_ERROR_FAILURE; if (!prevContainer || !nextContainer) return NS_ERROR_FAILURE; prevContainer->GetChildCount(&pcnt); nextContainer->GetChildCount(&ncnt); dsTreeNode->GetChildCount(&dsCount); //XXX What to do if the children count don't match for (PRInt32 i=0; i<ncnt; i++){ nsCOMPtr<nsISHEntry> pChild, nChild; nsCOMPtr<nsIDocShellTreeItem> dsTreeItemChild; prevContainer->GetChildAt(i, getter_AddRefs(pChild)); nextContainer->GetChildAt(i, getter_AddRefs(nChild)); if (dsCount > 0) dsTreeNode->GetChildAt(i, getter_AddRefs(dsTreeItemChild)); if (!dsTreeItemChild) return NS_ERROR_FAILURE; nsCOMPtr<nsIDocShell> dsChild(do_QueryInterface(dsTreeItemChild)); CompareFrames(pChild, nChild, dsChild, aLoadType, aIsFrameFound); } return result; }
// Frame data is stored in lpVHdr static LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr) { // If no data provided by driver (dropped frame) - nothing to do if (lpVHdr->dwBytesUsed == 0) return FALSE; int grayScaleSize = lpVHdr->dwBytesUsed/3; // RGB uses 24 BPP, GS is 8 BPP // Get pointer to our video grabber - remember, this is friend function VideoGrabber* videoGrabber = (VideoGrabber*) capGetUserData(hWnd); if (videoGrabber->mGrabNextFrame) { // Get video format from driver (including resolution) if (videoGrabber->mBitmapInfo == NULL) { // All these lines are run only once! I put them here and not in the constructor \ because I need to run them in context of callback. Strange though... DWORD videoFormatSize = capGetVideoFormatSize(videoGrabber->camhwnd); videoGrabber->mBitmapInfo = (PBITMAPINFO) new char[videoFormatSize]; capGetVideoFormat(videoGrabber->camhwnd, videoGrabber->mBitmapInfo, videoFormatSize); videoGrabber->mCurrentFrameGS = new BYTE[grayScaleSize]; videoGrabber->mCurrentFrameBlurred = new BYTE[grayScaleSize]; videoGrabber->mPreviousFrame = new BYTE[grayScaleSize]; } ApplyGrayScaleFilter(lpVHdr, videoGrabber->mCurrentFrameGS); // Pass current frame data to grayscale it // Blurring decreases noise. mBitmapInfo contains frame dimensions (width & height) ApplyAverageBlurFilter(videoGrabber->mCurrentFrameGS, videoGrabber->mBitmapInfo, videoGrabber->mCurrentFrameBlurred); if (videoGrabber->mPreviousFrameExists) { // Calculate difference between frames int differedPixelsNum = CompareFrames(videoGrabber->mCurrentFrameBlurred, videoGrabber->mPreviousFrame, videoGrabber->mBitmapInfo, videoGrabber->PIXELS_DIFFERENCE_TRESHOLD); videoGrabber->mMotionDetectedDuringLastSecond = (differedPixelsNum > videoGrabber->MOTION_TRESHOLD); // Motion detected! } memcpy(videoGrabber->mPreviousFrame, videoGrabber->mCurrentFrameBlurred, grayScaleSize); videoGrabber->mPreviousFrameExists = TRUE; // Now we have frame to compare with videoGrabber->mGrabNextFrame = FALSE; // frame for current second has been processed SetEvent(videoGrabber->mFrameProcessedEvent); // Signal about frame processing completion }
NS_IMETHODIMP nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType, PRUint32 aHistCmd) { nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsISHEntry> shEntry; // Keep note of requested history index in mRequestedIndex. mRequestedIndex = aIndex; nsCOMPtr<nsISHEntry> prevEntry; GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(prevEntry)); nsCOMPtr<nsISHEntry> nextEntry; GetEntryAtIndex(mRequestedIndex, PR_FALSE, getter_AddRefs(nextEntry)); nsCOMPtr<nsIHistoryEntry> nHEntry(do_QueryInterface(nextEntry)); if (!nextEntry || !prevEntry || !nHEntry) { mRequestedIndex = -1; return NS_ERROR_FAILURE; } // Send appropriate listener notifications PRBool canNavigate = PR_TRUE; // Get the uri for the entry we are about to visit nsCOMPtr<nsIURI> nextURI; nHEntry->GetURI(getter_AddRefs(nextURI)); if(mListener) { nsCOMPtr<nsISHistoryListener> listener(do_QueryReferent(mListener)); if (listener) { if (aHistCmd == HIST_CMD_BACK) { // We are going back one entry. Send GoBack notifications listener->OnHistoryGoBack(nextURI, &canNavigate); } else if (aHistCmd == HIST_CMD_FORWARD) { // We are going forward. Send GoForward notification listener->OnHistoryGoForward(nextURI, &canNavigate); } else if (aHistCmd == HIST_CMD_GOTOINDEX) { // We are going somewhere else. This is not reload either listener->OnHistoryGotoIndex(aIndex, nextURI, &canNavigate); } } } if (!canNavigate) { // If the listener asked us not to proceed with // the operation, simply return. return NS_OK; // XXX Maybe I can return some other error code? } nsCOMPtr<nsIURI> nexturi; PRInt32 pCount=0, nCount=0; nsCOMPtr<nsISHContainer> prevAsContainer(do_QueryInterface(prevEntry)); nsCOMPtr<nsISHContainer> nextAsContainer(do_QueryInterface(nextEntry)); if (prevAsContainer && nextAsContainer) { prevAsContainer->GetChildCount(&pCount); nextAsContainer->GetChildCount(&nCount); } nsCOMPtr<nsIDocShellLoadInfo> loadInfo; if (mRequestedIndex == mIndex) { // Possibly a reload case docShell = mRootDocShell; } else { // Going back or forward. if ((pCount > 0) && (nCount > 0)) { /* THis is a subframe navigation. Go find * the docshell in which load should happen */ PRBool frameFound = PR_FALSE; nsresult rv = CompareFrames(prevEntry, nextEntry, mRootDocShell, aLoadType, &frameFound); if (!frameFound) { // we did not successfully find the subframe in which // the new url was to be loaded. return error. mRequestedIndex = -1; return NS_ERROR_FAILURE; } return rv; } // (pCount >0) else docShell = mRootDocShell; } if (!docShell) { // we did not successfully go to the proper index. // return error. mRequestedIndex = -1; return NS_ERROR_FAILURE; } // Start the load on the appropriate docshell return InitiateLoad(nextEntry, docShell, aLoadType); }
int main(int argc, char* argv[]) { FILE* Log1; FILE* Log2; FILE* Opt; unsigned long StartFrame; frame CurrentFrame1; frame CurrentFrame2; unsigned long OldFrameNumber; bool HoldLog1; bool HoldLog2; HoldLog1=HoldLog2=FALSE; NoDifferences=TRUE; RememberedVars.Count=0; if(argc!=5) { fprintf(stderr, "Requires 4 arguments\n"); exit(1); } StartFrame=strtol(argv[1], NULL, 0); Log1=fopen(argv[2], "r"); if(!Log1) { fprintf(stderr, "Could not open file '%s'\n", argv[1]); exit(1); } Log2=fopen(argv[3], "r"); if(!Log2) { fprintf(stderr, "Could not open file '%s'\n", argv[2]); exit(1); } Opt=fopen(argv[4], "r"); if(!Opt) { fprintf(stderr, "Could not open options file '%s'\n", argv[3]); exit(1); } ParseConfig(Opt); fclose(Opt); if(StartFrame!=0) { fprintf(stderr, "Skipping initial frames...\n", StartFrame); ForwardToFrame(StartFrame-1, Log1, Log2); } fprintf(stderr, "Comparing logs at frame %d...\n", StartFrame); while(!feof(Log1) && !feof(Log2)) { int i; if(!HoldLog1) ParseFrame(Log1, &CurrentFrame1); else HoldLog1=FALSE; if(!HoldLog2) ParseFrame(Log2, &CurrentFrame2); else HoldLog2=FALSE; if(CurrentFrame1.Number==CurrentFrame2.Number) { if(!CompareFrames(&CurrentFrame1, &CurrentFrame2)) { int i; fprintf(stderr, "At previous frame (%d):\n", OldFrameNumber); for(i=0; i<RememberedVars.Count; i++) { fprintf(stderr, "\t%-10s <%s>\n", RememberedVars.Elements[i].Name, RememberedVars.Elements[i].Value); } exit(0); } } else { if(CurrentFrame1.Number>CurrentFrame2.Number) { fprintf(stderr, "Frame number %ld does not appear in log 1\n", CurrentFrame2.Number); HoldLog1=TRUE; } else { fprintf(stderr, "Frame number %ld does not appear in log 2\n", CurrentFrame1.Number); HoldLog2=TRUE; } } OldFrameNumber=CurrentFrame1.Number; for(i=0; i<RememberedVars.Count; i++) { strcpy(RememberedVars.Elements[i].Value, GetVariable(&CurrentFrame1, RememberedVars.Elements[i].Name)); } } fprintf(stderr, "Logs match\n"); exit(0); }
static bool RunTest(int bit_depth) { bool result = true; const int seq_len = 5; const int width = 100; const int height = 10; int luma_min = 16; int luma_max = 235; int chroma_zero = 128; schro_init(); // set up encoder SchroEncoder *encoder = schro_encoder_new(); schro_encoder_setting_set_double(encoder, "gop_structure", SCHRO_ENCODER_GOP_INTRA_ONLY); schro_encoder_setting_set_double(encoder, "rate_control", SCHRO_ENCODER_RATE_CONTROL_LOSSLESS); //schro_encoder_setting_set_double(encoder, "force_profile", SCHRO_ENCODER_PROFILE_VC2_SIMPLE); //schro_encoder_setting_set_double(encoder, "queue_depth", seq_len); //assert(seq_len <= SCHRO_LIMIT_FRAME_QUEUE_LENGTH); SchroVideoFormat *format = schro_encoder_get_video_format(encoder); if(format) { format->width = width; format->height = height; format->clean_width = format->width; format->clean_height = format->height; format->left_offset = 0; format->top_offset = 0; format->chroma_format = SCHRO_CHROMA_444; const SchroSignalRange range = (bit_depth == 12 ? SCHRO_SIGNAL_RANGE_12BIT_VIDEO : bit_depth == 10 ? SCHRO_SIGNAL_RANGE_10BIT_VIDEO : SCHRO_SIGNAL_RANGE_8BIT_VIDEO); schro_video_format_set_std_signal_range(format, range); luma_min = format->luma_offset; luma_max = format->luma_offset + format->luma_excursion; chroma_zero = format->chroma_offset; format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV; format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV; format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA; format->interlaced = false; format->frame_rate_numerator = 24; format->frame_rate_denominator = 1; format->aspect_ratio_numerator = 1; format->aspect_ratio_denominator = 1; schro_encoder_set_video_format(encoder, format); free(format); } else return false; schro_encoder_start(encoder); // create frame SchroFrame *start_frame = schro_frame_new_and_alloc(NULL, SCHRO_FRAME_FORMAT_U8_444, width, height); FillFrame<unsigned char>(start_frame, 16, 235, 128); const SchroFrameFormat schro_format = (bit_depth > 8 ? SCHRO_FRAME_FORMAT_S16_444 : SCHRO_FRAME_FORMAT_U8_444); SchroFrame *original_frame = schro_frame_new_and_alloc(NULL, schro_format, width, height); schro_frame_convert(original_frame, start_frame); SchroDecoder *decoder = schro_decoder_new(); // push frames to encoder for(int t = 0; t < seq_len; t++) { SchroFrame *new_frame = schro_frame_dup(original_frame); schro_encoder_push_frame(encoder, new_frame); } // pull packets out of encoder, pass to decoder int packets_out = 0; while(packets_out < seq_len) { SchroStateEnum encoder_state = schro_encoder_wait(encoder); if(encoder_state == SCHRO_STATE_HAVE_BUFFER || encoder_state == SCHRO_STATE_END_OF_STREAM) { int n_decodable_frames = -1; SchroBuffer *buffer = schro_encoder_pull(encoder, &n_decodable_frames); if(buffer) { const int parse_code = buffer->data[4]; if(SCHRO_PARSE_CODE_IS_SEQ_HEADER(parse_code) || SCHRO_PARSE_CODE_IS_AUXILIARY_DATA(parse_code) || SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) { schro_decoder_push(decoder, buffer); //schro_buffer_unref(buffer); if(SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) { packets_out++; } } } } else { assert(encoder_state == SCHRO_STATE_NEED_FRAME); assert(encoder_state != SCHRO_STATE_AGAIN); // yeah, redundant schro_encoder_end_of_stream(encoder); } } // pull frames out of decoder int frames_out = 0; while(frames_out < seq_len) { int decoder_state = schro_decoder_wait(decoder); if(decoder_state == SCHRO_DECODER_FIRST_ACCESS_UNIT) { SchroVideoFormat *format = schro_decoder_get_video_format(decoder); if(format) { assert(format->width == width); assert(format->height == height); assert(format->chroma_format == SCHRO_CHROMA_444); assert(format->luma_offset == luma_min); assert(format->luma_offset + format->luma_excursion == luma_max); assert(format->chroma_offset = chroma_zero); free(format); } } else if(decoder_state == SCHRO_DECODER_NEED_BITS) { schro_decoder_push_end_of_stream(decoder); } else if(decoder_state == SCHRO_DECODER_NEED_FRAME) { SchroFrame *decoder_frame = schro_frame_new_and_alloc(NULL, schro_format, width, height); schro_decoder_add_output_picture(decoder, decoder_frame); } else if(decoder_state == SCHRO_DECODER_OK || decoder_state == SCHRO_DECODER_EOS) { SchroFrame *decoder_frame = schro_decoder_pull(decoder); if(decoder_frame) { frames_out++; bool match = CompareFrames(decoder_frame, original_frame); //std::cout << (match ? "Match!" : "No Match!") << " " << std::endl; if(!match) { // output doesn't match input, so print the values of the // first line of the first component to see what went in and out PrintFirstLine(original_frame); std::cout << "==========" << std::endl; PrintFirstLine(decoder_frame); std::cout << "==========" << std::endl; result = false; } schro_frame_unref(decoder_frame); } } } schro_frame_unref(original_frame); schro_frame_unref(start_frame); schro_decoder_free(decoder); schro_encoder_free(encoder); return result; }