diff options
author | Fox Caminiti <fox@foxcam.net> | 2022-08-04 12:33:54 -0400 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2022-08-04 12:33:54 -0400 |
commit | bccb1d61907fea45c5e84b29499989f7cee104a5 (patch) | |
tree | 8e70ecab3bce134d2b5100cfd67f37dee2dccda3 | |
parent | 8875d0226f0d38a1e5ef946e56cd15810627f5ac (diff) |
loaded bitmap wrap buffer seems stable
-rw-r--r-- | createcalls.cpp | 2 | ||||
-rw-r--r-- | ffmpeg_backend.cpp | 63 | ||||
-rw-r--r-- | main.cpp | 22 | ||||
-rw-r--r-- | main.h | 1 | ||||
-rw-r--r-- | memory.cpp | 21 | ||||
-rw-r--r-- | my_imgui_widgets.cpp | 21 |
6 files changed, 106 insertions, 24 deletions
diff --git a/createcalls.cpp b/createcalls.cpp index 892be0a..a767db8 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -266,6 +266,8 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory) project_layer *Layer2 = Layer_Init(File, Memory); AV_Init(Source2, &Layer2->BitmapInfo, Memory); Layer_InitSource(Layer2, Source2, Memory); + Layer2->StartFrame = 11; + Layer2->EndFrame = 23; // AddEffect(File->Layer[0], Memory, 2); // project_layer *Layer1 = CreateDebugLayer(&File, &Memory, 9, 14); diff --git a/ffmpeg_backend.cpp b/ffmpeg_backend.cpp index dfc1241..1f920ba 100644 --- a/ffmpeg_backend.cpp +++ b/ffmpeg_backend.cpp @@ -272,40 +272,81 @@ bool32 AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo, memory * uint16 BytesPerPixel = Source->Info.BytesPerPixel; int32 Pitch = Width*BytesPerPixel; - // probably should rename this memory_table *Table = &Memory->Slot[B_LoadedBitmaps]; + + // First check whether we'd run over the buffer at the current + // position, and reset it if so. uint64 Size = Bitmap_CalcTotalBytes(Width, Height, BytesPerPixel); if (Table->CurrentPosition + Size > Table->Size) { Table->CurrentPosition = 0; Table->PointerIndex = 0; } cached_bitmap *Bitmap = &Memory->Bitmap[Table->PointerIndex]; - if (Table->PointerIndex < Table->NumberOfPointers) { + + // Next, if there's a pointer in front of the current position, + // check whether it's far away enough so that the size fits. + bool32 BS = true; + if (Bitmap->Data) { + uint64 BytesBetween = (uint8 *)Bitmap->Data - ((uint8 *)Table->Address + Table->CurrentPosition); + if (BytesBetween > Size) { + int16 StopAt = Table->NumberOfPointers - 1; + while (StopAt > Table->PointerIndex - 1) { + Memory->Bitmap[StopAt + 1] = Memory->Bitmap[StopAt]; + StopAt--; + } + Table->NumberOfPointers++; + BS = false; + } + } + // If it doesn't fit, then we need to dereference the pointers + // until we have enough space. + if ((Table->PointerIndex < Table->NumberOfPointers) && BS) + { bool32 Avail = false; - void *DataStart = Memory->Bitmap[Table->PointerIndex].Data; + void *AddressStart = (void *)((uint8 *)Table->Address + Table->CurrentPosition); + uint32 Amount = 0; while(!Avail) { - void *Data2 = Memory->Bitmap[Table->PointerIndex+1].Data; - uint64 BytesBetween = (uint8 *)Data2 - (uint8 *)DataStart; - if (BytesBetween < Size) { - Memory->Bitmap[Table->PointerIndex+1].SourceOwner = NULL; - Table->PointerIndex++; + // Bail out if we're on the last index, as we don't need to do anything else. + if (Table->PointerIndex != Table->NumberOfPointers - 1) { + void *Data2 = Memory->Bitmap[Table->PointerIndex+1].Data; + uint64 BytesBetween = (uint8 *)Data2 - (uint8 *)AddressStart; + if (BytesBetween < Size) { + int16 StopAt = Table->PointerIndex; + while (StopAt < Table->NumberOfPointers - 1) { + Memory->Bitmap[StopAt] = Memory->Bitmap[StopAt + 1]; + StopAt++; + } + Amount++; + Table->NumberOfPointers--; + if (Amount > 2) { + Amount += 0; + } + } else { + Avail = true; + } } else { Avail = true; } - Table->NumberOfPointers--; } } - Table->NumberOfPointers++; + // Increment the total number of pointers if the bitmap is + // empty, i.e. we're at the first iteration of the buffer loop. + if (!Bitmap->Data) { + Table->NumberOfPointers++; + } Bitmap->Data = AllocateMemory(Memory, Size, B_LoadedBitmaps); if (!Bitmap->Data) { Assert(0); } Bitmap->SourceOwner = Source; Bitmap->Frame = FrameToSeek; - Bitmap->Index = Table->PointerIndex; Table->PointerIndex++; void *Buffer = Bitmap->Data; + // No two pointers on the table should hold the same data + // address or be empty. + Debug_Memory_Assert_Cohesion(Memory, Table); + int out_linesize[4] = { Pitch, Pitch, Pitch, Pitch }; uint8 *dst_data[4] = { (uint8 *)Buffer, (uint8 *)Buffer + Width*Height*BytesPerPixel, (uint8 *)Buffer + Width*Height*BytesPerPixel*2, (uint8 *)Buffer + Width*Height*BytesPerPixel*3 }; @@ -78,17 +78,21 @@ MainFunction(main_sdl *Main, memory *Memory, Bitmap_Clear(CompBuffer->UnpackedBuffer, CompBuffer->Width, CompBuffer->Height, CompBuffer->BytesPerPixel); for (int i = 0; i < File->NumberOfLayers; i++) { project_layer *Layer = File->Layer[i]; - if (State->UpdateKeyframes) { - for (int p = 0; p < Layer->NumberOfEffects; p++) { - for (int o = 0; o < Layer->Effect[p]->NumberOfProperties; o++) { - CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Effect[p]->Property[o]); - } - } - for (int r = 0; r < AmountOf(Layer->Property); r++) { - CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Property[r]); + if (Layer->StartFrame <= File->CurrentFrame && + Layer->EndFrame >= File->CurrentFrame) + { + if (State->UpdateKeyframes) { + for (int p = 0; p < Layer->NumberOfEffects; p++) { + for (int o = 0; o < Layer->Effect[p]->NumberOfProperties; o++) { + CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Effect[p]->Property[o]); + } + } + for (int r = 0; r < AmountOf(Layer->Property); r++) { + CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Property[r]); + } } + Layer_UpdateBitmap(Layer, Memory, File->CurrentFrame); } - Layer_UpdateBitmap(Layer, Memory, File->CurrentFrame); } State->UpdateKeyframes = false; QueueCurrentFrame(File, CompBuffer, State); @@ -61,7 +61,6 @@ struct cached_bitmap { source *SourceOwner; // Which source it belongs to. Currently used to dereference the bitmap. void *Data; // Unpacked data loaded from the source file. uint32 Frame; // What frame it is. - uint32 Index; // Index in memory. }; struct memory { @@ -29,3 +29,24 @@ Memory_NormalizedPosition(void *StartingPointer, uint32 Amount, uint32 Size, voi Result = (real32)PointerLocationSize / (real32)TotalSize; return Result; } + +static void +Debug_Memory_Assert_Cohesion(memory *Memory, memory_table *Table) +{ +#if DEBUG + for (uint32 i = 0; i < Table->NumberOfPointers; i++) { + cached_bitmap *CurrentBitmap = &Memory->Bitmap[i]; + Assert(CurrentBitmap->Data); + for (uint32 a = 0; a < Table->NumberOfPointers; a++) { + if (a == i) { + continue; + } + cached_bitmap *OtherBitmap = &Memory->Bitmap[a]; + if (OtherBitmap->Data == CurrentBitmap->Data) { + Assert(0); + } + } + } +#else +#endif +} diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index f93866a..b4114e7 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -98,6 +98,14 @@ ImGui_DebugMemoryViewer(project_data *File, memory *Memory) ImVec2 Max = ImVec2(Min.x + 2, ViewportMax.y); draw_list->AddLine(Min, Max, LineColor); } + // CurrentPosition line + { + uint32 LineColor = IM_COL32(000, 100, 200, 200); + real32 CurPosMB = (real32)Table->CurrentPosition/1024/1024; + ImVec2 Min = ImVec2(ViewportMin.x + (CurPosMB/IncrementMB * ScreenIncrement), ViewportMin.y); + ImVec2 Max = ImVec2(Min.x + 2, ViewportMax.y); + draw_list->AddLine(Min, Max, LineColor); + } for (uint32 i = 0; i < Table->NumberOfPointers; i++) { if (Memory->Bitmap[i].SourceOwner) { @@ -117,7 +125,7 @@ ImGui_DebugMemoryViewer(project_data *File, memory *Memory) ImVec4 col = ImColor::HSV(Pos, 0.3, 0.6, 1.0f); uint64 BitmapSize = Bitmap_CalcTotalBytes(Source->Info.Width, Source->Info.Height, Source->Info.BytesPerPixel); - if (BitmapSize > BytesBetween) { + if (BitmapSize > BytesBetween && i != Table->NumberOfPointers - 1) { col = ImColor::HSV(Pos, 1.0, 1.0, 1.0f); } @@ -135,7 +143,9 @@ ImGui_DebugMemoryViewer(project_data *File, memory *Memory) ImGui::PopStyleColor(); if (ImGui::IsItemHovered()) { char buf[1024]; - sprintf(buf, "Source owner: %s\nSize: %.02f MB\n Frame number: %i", Memory->Bitmap[i].SourceOwner->Path, SizeReal, Memory->Bitmap[i].Frame); + sprintf(buf, "Source owner: %s\nSize: %.02f MB\n Frame number: %i\n Index: %i", + Memory->Bitmap[i].SourceOwner->Path, SizeReal, + Memory->Bitmap[i].Frame, i); ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::TextUnformatted(buf); @@ -147,6 +157,11 @@ ImGui_DebugMemoryViewer(project_data *File, memory *Memory) // draw_list->AddRectFilled(Min, Max, IM_COL32(200, 200, 200, 255)); } } + ImGui::SetCursorScreenPos(ImVec2(ViewportMin.x, ViewportMax.y - CubeHeight*2)); + char buf[1024]; + sprintf(buf, "Current index: %i\nAmount of pointers: %i", + Table->PointerIndex, Table->NumberOfPointers); + ImGui::Text(buf); ImGui::End(); } @@ -544,7 +559,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::BeginChild("Topbar", TopbarSize, true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar); - ImGui::Text + // ImGui::Text /* ImGui::Button("V", TopbarButtonSize); ImGui::SameLine(); ImGui::Button("V", TopbarButtonSize); ImGui::SameLine(); |