⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvavicapture.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    Result := capDriverConnect(FHWnd, Driver);
    FConnected := Result;

    if FConnected then
    begin
      // if connected successfully, update the property
      FDriverIndex := Driver;
      UpdateCaps;
      FCaptureSettings.Update;
      FAudioFormat.Update;
      UpdateCaptureStatus;

    end
    else
      // if not, trigger an exception
      raise EInvalidDriverIndexError.Create(Driver, Drivers.Count - 1);
  end;
  AdjustSize;
end;

function TJvAVICapture.Disconnect: Boolean;
begin
  Result := capDriverDisconnect(FHWnd);
  UpdateCaptureStatus;
  FConnected := False;
end;

function TJvAVICapture.ShowDialog(Dialog: TJvVideoDialog): Boolean;
begin
  Result := False;
  if FHWnd <> 0 then
  begin
    case Dialog of
      vdSource:
        Result := capDlgVideoSource(FHWnd);
      vdFormat:
        Result := capDlgVideoFormat(FHWnd);
      vdDisplay:
        Result := capDlgVideoDisplay(FHWnd);
      vdCompression:
        Result := capDlgVideoCompression(FHWnd);
    end;
    // update everything to reflect user changes
    UpdateCaps;
    VideoFormat.Update;
    AudioFormat.Update;
    CaptureSettings.Update;
    SetBounds(Left, Top, Width, Height);
  end;
end;

function TJvAVICapture.StartPreview: Boolean;
begin
  // if we have a valid window that is not already previewing
  if (FHWnd <> 0) and not FPreviewing then
  begin
    capPreviewRate(FHWnd, FPreviewFrameDelay);
    FPreviewing := capPreview(FHWnd, True);
    UpdateCaptureStatus;
    VideoFormat.Update;
    if FPreviewing then
    begin
      FOverlaying := False;
      RestartCallbacks;
    end;
    Result := FPreviewing;
  end
  else
    Result := False;
end;

function TJvAVICapture.StopPreview: Boolean;
begin
  // if we have a valid window doing previewing
  // then the result is the result of capPreview
  Result := (FHWnd <> 0) and FPreviewing and capPreview(FHWnd, False);

  // if succesfully stopped preview, update internal values
  if Result then
  begin
    UpdateCaptureStatus;
    FPreviewing := False;
    StopCallbacks;
  end;
end;

function TJvAVICapture.StartCapture: Boolean;
begin
  if (FHWnd <> 0) and not FCapturing and ApplyCaptureSettings and
    ApplyAudioFormat then
  begin
    UpdateCaptureStatus;
    VideoFormat.Update;
    FCapturing := capCaptureSequence(FHWnd);
    if FCapturing then
      RestartCallbacks;
    Result := FCapturing;
  end
  else
    Result := False;
end;

function TJvAVICapture.StartCaptureNoFile: Boolean;
begin
  if (FHWnd <> 0) and not FCapturing and ApplyCaptureSettings and
    ApplyAudioFormat then
  begin
    UpdateCaptureStatus;
    VideoFormat.Update;
    FCapturing := capCaptureSequenceNoFile(FHWnd);
    FNoFile := True;
    if FCapturing then
      RestartCallbacks;
    Result := FCapturing;
  end
  else
    Result := False;
end;

function TJvAVICapture.StopCapture: Boolean;
begin
  Result := (FHWnd <> 0) and FCapturing and capCaptureStop(FHWnd);
  if Result then
  begin
    FCapturing := False;
    StopCallbacks;
  end;
end;

function TJvAVICapture.AbortCapture: Boolean;
begin
  Result := (FHWnd <> 0) and FCapturing and capCaptureAbort(FHWnd);
  if Result then
  begin
    FCapturing := False;
    StopCallbacks;
  end;
end;

function TJvAVICapture.StartSingleFrameCapture: Boolean;
begin
  Result := (FHWnd <> 0) and not FSingleFrameCapturing and
    capCaptureSingleFrameOpen(FHWnd);
  if Result then
  begin
    UpdateCaptureStatus;
    VideoFormat.Update;
    RestartCallbacks;
    FSingleFrameCapturing := True;
  end;
end;

function TJvAVICapture.CaptureFrame: Boolean;
begin
  Result := (FHWnd <> 0) and FSingleFrameCapturing and
    capCaptureSingleFrame(FHWnd);
  UpdateCaptureStatus;
  VideoFormat.Update;
end;

function TJvAVICapture.StopSingleFrameCapture: Boolean;
begin
  Result := (FHWnd <> 0) and FSingleFrameCapturing and
    capCaptureSingleFrameClose(FHWnd);
  if Result then
  begin
    UpdateCaptureStatus;
    VideoFormat.Update;
    StopCallbacks;
    FSingleFrameCapturing := False;
  end;
end;

function TJvAVICapture.StartOverlay: Boolean;
begin
  if (FHWnd <> 0) and not FOverlaying then
  begin
    capPreviewRate(FHWnd, FPreviewFrameDelay);
    FOverlaying := capOverlay(FHWnd, True);
    UpdateCaptureStatus;
    VideoFormat.Update;
    if FOverlaying then
    begin
      FPreviewing := False;
      RestartCallbacks;
    end;
    Result := FOverlaying;
  end
  else
    Result := False;
end;

function TJvAVICapture.StopOverlay: Boolean;
begin
  Result := (FHWnd <> 0) and FOverlaying and capOverlay(FHWnd, False);
  if Result then
  begin
    UpdateCaptureStatus;
    FOverlaying := False;
    StopCallbacks;
  end;
end;

function TJvAVICapture.ApplyCaptureSettings: Boolean;
begin
  Result := CaptureSettings.Apply;
end;

function TJvAVICapture.ApplyAudioFormat: Boolean;
begin
  Result := AudioFormat.Apply;
end;

function TJvAVICapture.SaveAs(Name: string): Boolean;
begin
  Result := (FHWnd <> 0) and capFileSaveAs(FHWnd, PChar(Name));
end;

function TJvAVICapture.SetInfoChunk(const Chunk: TCAPINFOCHUNK): Boolean;
begin
  Result := (FHWnd <> 0) and capFileSetInfoChunk(FHWnd, @Chunk);
end;

function TJvAVICapture.SaveDIB(Name: string): Boolean;
begin
  Result := (FHWnd <> 0) and capFileSaveDIB(FHWnd, PChar(Name));
end;

function TJvAVICapture.CopyToClipboard: Boolean;
begin
  Result := (FHWnd <> 0) and capEditCopy(FHWnd);
end;

function TJvAVICapture.GrabFrame(Stop: Boolean): Boolean;
begin
  Result := False;
  if FHWnd <> 0 then
    if Stop then
    begin
      FPreviewing := False;
      FOverlaying := False;
      Result := capGrabFrame(FHWnd);
    end
    else
      Result := capGrabFrameNoStop(FHWnd);
end;

procedure TJvAVICapture.DoError(ErrId: Integer; Str: string);
begin
  if csDesigning in ComponentState then
    Windows.MessageBox(WindowHandle, PChar(Str), PChar(RsErrorMessagePrefix + IntToStr(ErrId)), MB_ICONERROR);
  if Assigned(FOnError) then
    FOnError(Self, ErrId, Str);
end;

procedure TJvAVICapture.DoStatus(nId: Integer; Str: string);
begin
  UpdateCaptureStatus;
  if Assigned(FOnStatus) then
    FOnStatus(Self, nId, Str);
end;

procedure TJvAVICapture.DoYield;
begin
  UpdateCaptureStatus;
  if Assigned(FOnYield) then
    FOnYield(Self);
end;

procedure TJvAVICapture.DoFrame(videoHdr: PVIDEOHDR);
begin
  if Assigned(FOnFrame) then
    FOnFrame(Self, videoHdr);
end;

procedure TJvAVICapture.DoVideoStream(videoHdr: PVIDEOHDR);
begin
  if Assigned(FOnVideoStream) then
    FOnVideoStream(Self, videoHdr);
end;

procedure TJvAVICapture.DoWaveStream(waveHdr: PWaveHdr);
begin
  if Assigned(FOnWaveStream) then
    FOnWaveStream(Self, waveHdr);
end;

procedure TJvAVICapture.DoCapControl(nState: Integer; var AResult: Boolean);
begin
  AResult := True;
  if Assigned(FOnCapControl) then
    FOnCapControl(Self, nState, AResult);
end;

procedure TJvAVICapture.SetVideoLeft(const Value: Integer);
var
  P: TPoint;
begin
  P.X := Value;
  P.Y := VideoTop;
  if capSetScrollPos(FHWnd, @P) then
    FVideoLeft := Value;
end;

procedure TJvAVICapture.SetVideoTop(const Value: Integer);
var
  P: TPoint;
begin
  P.X := VideoLeft;
  P.Y := Value;
  if capSetScrollPos(FHWnd, @P) then
    FVideoTop := Value;
end;

function TJvAVICapture.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
  // always possible to do autosizing
  Result := True;

  // reload video size
  FVideoFormat.Update;

  // force the width and height to be equal
  // to the one from the video (with a minimum value set
  // in case there is no video yet)
  NewHeight := Max(cMinHeight, FVideoFormat.Height);
  NewWidth := Max(cMinWidth, FVideoFormat.Width);
end;

procedure TJvAVICapture.SetSingleFrameCapturing(const Value: Boolean);
begin
  if Value then
    StartSingleFrameCapture
  else
    StopSingleFrameCapture;
end;

//=== EInvalidDriverIndexError ===============================================

constructor EInvalidDriverIndexError.Create(Index: TJvDriverIndex; MaxIndex: TJvDriverIndex);
begin
  inherited CreateFmt(RsEInvalidDriverIndex, [Index, MaxIndex]);
end;

{$IFDEF UNITVERSIONING}
initialization
  RegisterUnitVersion(HInstance, UnitVersioning);

finalization
  UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -