MF SinkWriter 写入样本失败

2023-12-02

我正在尝试使用 MediaFoundation 将 ID3D11Texture2D 编码为 mp4。下面是我当前的代码。

初始化接收器写入器

private int InitializeSinkWriter(String outputFile, int videoWidth, int videoHeight)
    {
        IMFMediaType mediaTypeIn = null;
        IMFMediaType mediaTypeOut = null;
        IMFAttributes attributes = null;

        int hr = 0;

        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateAttributes(out attributes, 1);
        if (Succeeded(hr)) hr = (int)attributes.SetUINT32(MFAttributesClsid.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1);            
        if (Succeeded(hr)) hr = (int)attributes.SetUINT32(MFAttributesClsid.MF_LOW_LATENCY, 1);

        // Create the sink writer 
        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateSinkWriterFromURL(outputFile, null, attributes, out sinkWriter);

        // Create the output type
        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateMediaType(out mediaTypeOut);
        if (Succeeded(hr)) hr = (int)mediaTypeOut.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
        if (Succeeded(hr)) hr = (int)mediaTypeOut.SetGUID(MFAttributesClsid.MF_TRANSCODE_CONTAINERTYPE, MFTranscodeContainerType.MPEG4);
        if (Succeeded(hr)) hr = (int)mediaTypeOut.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, MFMediaType.H264);
        if (Succeeded(hr)) hr = (int)mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_AVG_BITRATE, videoBitRate);
        if (Succeeded(hr)) hr = (int)mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (int)MFVideoInterlaceMode.Progressive);            

        if (Succeeded(hr)) hr = (int)MFExtern.MFSetAttributeSize(mediaTypeOut, MFAttributesClsid.MF_MT_FRAME_SIZE, videoWidth, videoHeight);
        if (Succeeded(hr)) hr = (int)MFExtern.MFSetAttributeRatio(mediaTypeOut, MFAttributesClsid.MF_MT_FRAME_RATE, VIDEO_FPS, 1);
        if (Succeeded(hr)) hr = (int)MFExtern.MFSetAttributeRatio(mediaTypeOut, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
        if (Succeeded(hr)) hr = (int)sinkWriter.AddStream(mediaTypeOut, out streamIndex);



        // Create the input type 
        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateMediaType(out mediaTypeIn);
        if (Succeeded(hr)) hr = (int)mediaTypeIn.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
        if (Succeeded(hr)) hr = (int)mediaTypeIn.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, MFMediaType.ARGB32);
        if (Succeeded(hr)) hr = (int)mediaTypeIn.SetUINT32(MFAttributesClsid.MF_SA_D3D11_AWARE, 1);
        if (Succeeded(hr)) hr = (int)mediaTypeIn.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (int)MFVideoInterlaceMode.Progressive);
        if (Succeeded(hr)) hr = (int)MFExtern.MFSetAttributeSize(mediaTypeIn, MFAttributesClsid.MF_MT_FRAME_SIZE, videoWidth, videoHeight);
        if (Succeeded(hr)) hr = (int)MFExtern.MFSetAttributeRatio(mediaTypeIn, MFAttributesClsid.MF_MT_FRAME_RATE, VIDEO_FPS, 1);
        if (Succeeded(hr)) hr = (int)MFExtern.MFSetAttributeRatio(mediaTypeIn, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
        if (Succeeded(hr)) hr = (int)sinkWriter.SetInputMediaType(streamIndex, mediaTypeIn, null);


        // Start accepting data
        if (Succeeded(hr)) hr = (int)sinkWriter.BeginWriting();


        COMBase.SafeRelease(mediaTypeOut);
        COMBase.SafeRelease(mediaTypeIn);

        return hr;
    }

书写框架

 int hr = 0;
        IMFSample sample = null;
        IMFMediaBuffer buffer = null;
        IMF2DBuffer p2Dbuffer = null;
        object texNativeObject = Marshal.GetObjectForIUnknown(surface.NativePointer);

        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateDXGISurfaceBuffer(new Guid("6f15aaf2-d208-4e89-9ab4-489535d34f9c"), texNativeObject, 0, false, out p2Dbuffer);

        buffer = MFVideoEncoderST.ReinterpretCast<IMF2DBuffer,IMFMediaBuffer>(p2Dbuffer);
        int length=0;
        if (Succeeded(hr)) hr = (int)p2Dbuffer.GetContiguousLength(out length);
        if (Succeeded(hr)) hr = (int)buffer.SetCurrentLength(length);


        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateVideoSampleFromSurface(null, out sample);

        if (Succeeded(hr)) hr = (int)sample.AddBuffer(buffer);
        if (Succeeded(hr)) hr = (int)sample.SetSampleTime(prevRecordingDuration);
        if (Succeeded(hr)) hr = (int)sample.SetSampleDuration((recordDuration - prevRecordingDuration));

        if (Succeeded(hr)) hr = (int)sinkWriter.WriteSample(streamIndex, sample);


        COMBase.SafeRelease(sample);
        COMBase.SafeRelease(buffer);

使用 MFTRACE 我收到以下错误。

    02:48:04.99463 CMFSinkWriterDetours::WriteSample @024BEA18 Stream Index 0x0, Sample @17CEACE0, Time 571ms, Duration 16ms, Buffers 1, Size 4196352B,2088,2008 02:48:04.99465 CMFSinkWriterDetours::WriteSample @024BEA18 failed hr=0x887A0005 (null)2088,2008 
02:48:05.01090 CMFSinkWriterDetours::WriteSample @024BEA18 Stream Index 0x0, Sample @17CE9FC0, Time 587ms, Duration 17ms, Buffers 1, Size 4196352B,2088,2008 02:48:05.01091 CMFSinkWriterDetours::WriteSample @024BEA18 failed hr=0x887A0005 (null)2088,2008 
02:48:05.02712 CMFSinkWriterDetours::WriteSample @024BEA18 Stream Index 0x0, Sample @17CEACE0, Time 604ms, Duration 16ms, Buffers 1, Size 4196352B,2088,2008 02:48:05.02713 CMFSinkWriterDetours::WriteSample @024BEA18 failed hr=0x887A0005 (null)

谁能告诉我我的代码有什么问题吗?我只能生成 0 字节的 mp4 文件。


我在这里遇到了一些潜在的问题。罗曼提到了两个大问题,所以我将详细说明它们。我还有一些其他的批评/建议给你。

不使用IMFDXGIDeviceManager

为了在 Media Foundation 中使用硬件加速,您需要创建一个 DirectX 设备管理器对象,可以是IDirect3DDeviceManager9对于 DX9 或您的情况IMFDXGIDeviceManager对于 DXGI。我强烈建议阅读该接口的所有 MSDN 文档。之所以有必要,是因为同一个 DX 设备必须在所使用的所有协作硬件 MF 转换之间共享,因为它们都需要访问设备控制的共享 GPU 内存,并且每个设备在工作时都需要对设备进行独占控制,因此需要一个锁定系统。设备管理器对象提供了该锁定系统,也是为一个或多个转换提供 DX 设备的标准方式。对于 DXGI,您可以使用以下命令创建它MFCreateDXGIDeviceManager.

从那里,您需要创建 DX11 设备,并调用IMFDXGIDeviceManager::ResetDevice与您的 DX11 设备。然后,您需要为 Sink Writer 本身设置设备管理器,这在您上面提供的代码中没有完成。这是这样完成的:

// ... inside your InitializeSinkWriter function that you listed above

// I'm assuming you've already created and set up the DXGI device manager elsewhere
IMFDXGIDeviceManager pDeviceManager;

// Passing 3 as the argument because we're adding 3 attributes immediately, saves re-allocations
if (Succeeded(hr)) hr = (int)MFExtern.MFCreateAttributes(out attributes, 3);
if (Succeeded(hr)) hr = (int)attributes.SetUINT32(MFAttributesClsid.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1);            
if (Succeeded(hr)) hr = (int)attributes.SetUINT32(MFAttributesClsid.MF_LOW_LATENCY, 1);

// Here's the key piece!
if (Succeeded(hr)) hr = (int)attributes.SetUnknown(MFAttributesClsid.MF_SINK_WRITER_D3D_MANAGER, pDeviceManager);

// Create the sink writer 
if (Succeeded(hr)) hr = (int)MFExtern.MFCreateSinkWriterFromURL(outputFile, null, attributes, out sinkWriter);

这实际上将启用 D3D11 对硬件编码器的支持,并允许其访问读取Texture2D你正在路过。值得注意的是MF_SINK_WRITER_D3D_MANAGER适用于 DX9 和 DXGI 设备管理器。


编码器缓冲多个IMFSample相同纹理的实例

这也是问题的潜在原因 - 至少它会导致很多意外行为,即使它不是明显问题的原因。根据 Roman 的评论,许多编码器将缓冲多个帧作为其编码过程的一部分。使用 Sink Writer 时您不会看到这种行为,因为它会为您处理所有细节工作。然而,您想要完成的任务(即发送 D3D11 纹理作为输入帧)的级别足够低,您开始不得不担心 Sink Writer 使用的编码器 MFT 的内部细节。

大多数视频编码器 MFT 将使用一定大小的内部缓冲区来存储最后一个N样品通过提供IMFTransform::ProcessInput。这具有副作用,即在生成任何输出之前必须提供多个样本作为输入。视频编码器需要按顺序访问多个样本,因为它们使用后续帧来确定如何对当前帧进行编码。换句话说,如果解码器正在处理帧 0,它可能还需要查看帧 1、2 和 3。从技术角度来看,这是因为帧间预测和运动估计。一旦编码器完成处理最旧的样本,它就会生成一个输出缓冲区(另一个IMFSample对象,但这次在输出端通过IMFTransform::ProcessOutput)然后丢弃它正在处理的输入样本(通过调用IUnknown::Release),然后请求更多输入,并最终进入下一帧。您可以在 MSDN 文章中阅读有关此过程的更多信息在编码器中处理数据

正如 Roman 所提到的,这意味着你正在封装一个ID3D11Texture2D里面一个IMFMediaBuffer里面一个IMFSample然后将其传递给 Sink Writer。作为编码过程的一部分,该样本可能由编码器缓冲。当编码器工作时,该内容Texture2D可能正在发生变化,这可能会导致各种问题。即使这不会导致程序错误,它也肯定会导致非常奇怪的编码视频输出。想象一下,如果编码器试图预测一帧的视觉内容在下一帧中如何变化,然后两帧的实际视觉内容从编码器下更新!

发生这个特定问题是因为编码器只有一个指向您的指针引用IMFSample实例,它最终只是一个指向你的实例的指针ID3D11Texture2D对象,该对象是一种对可变图形内存的指针引用。最终,该图形内存的内容会由于程序的其他部分而发生变化,但由于更新的始终是相同的 GPU 纹理,因此您发送给编码器的每个样本都指向相同的单个纹理。这意味着每当您通过更改 GPU 内存来更新纹理时,所有活动的IMFSample对象将反映这些变化,因为它们都有效地指向相同的 GPU 纹理。

要解决此问题,您需要分配多个ID3D11Texture2D对象,这样您就可以将一个纹理与一个纹理配对IMFSample将其提供给 Sink Writer 时。这将通过使每个样本指向唯一的纹理来解决所有样本都指向同一个 GPU 纹理的问题。不过,您不一定知道需要创建多少纹理,因此处理此问题的最安全方法是编写自己的纹理分配器。这仍然可以在 C# 中完成,因为 MediaFoundation.NET 已经定义了您需要使用的接口。

分配器应该维护一个“空闲”列表SharpDX.Texture2D对象 - 那些当前未被接收器写入器/编码器使用的对象。您的程序应该能够从分配器请求新的纹理对象,在这种情况下,它将从空闲列表中返回一个对象,或者创建一个新的纹理来满足该请求。

下一个问题是知道什么时候IMFSample对象已被编码器丢弃,因此您可以将附加的纹理添加回空闲列表。碰巧的是,MFCreateVideoSampleFromSurface您当前使用的函数分配实现以下功能的样本IMFTrackedSample界面。您将需要该界面,以便在释放样本时收到通知,以便您可以回收Texture2D对象。

诀窍是你必须告诉样本:you是分配器。首先,您的分配器类需要实现IMFAsyncCallback。如果您通过以下方式在示例上设置分配器类IMFTrackedSample::SetAllocator,你的分配器的IMFAsyncCallback::Invoke方法将被调用,带有IMFAsyncResult每当编码器释放样本时作为参数传递。下面是分配器类的一般示例。

sealed class TextureAllocator : IMFAsyncCallback, IDisposable
{
    private ConcurrentStack<SharpDX.Direct3D11.Texture2D> m_freeStack;
    private static readonly Guid s_IID_ID3D11Texture2D = new Guid("6f15aaf2-d208-4e89-9ab4-489535d34f9c");

    // If all textures are the exact same size and color format,
    // consider making those parameters private class members and
    // requiring they be specified as arguments to the constructor.
    public TextureAllocator()
    {
        m_freeStack = new ConcurrentStack<SharpDX.Direct3D11.Texture2D>();
    }

    private bool disposedValue = false;
    private void Dispose(bool disposing)
    {
        if(!disposedValue)
        {
            if(disposing)
            {
                // Dispose managed resources here
            }

            if(m_freeStack != null)
            {
                SharpDX.Direct3D11.Texture2D texture;
                while(m_freeStack.TryPop(out texture))
                {
                    texture.Dispose();
                }
                m_freeStack = null;
            }

            disposedValue = true;
        }
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    ~TextureAllocator()
    {
        Dispose(false);
    }

    private SharpDX.Direct3D11.Texture2D InternalAllocateNewTexture()
    {
        // Allocate a new texture with your format, size, etc here.
    }

    public SharpDX.Direct3D11.Texture2D AllocateTexture()
    {
        SharpDX.Direct3D11.Texture2D existingTexture;
        if(m_freeStack.TryPop(out existingTexture))
        {
            return existingTexture;
        }
        else
        {
            return InternalAllocateNewTexture();
        }
    }

    public IMFSample CreateSampleAndAllocateTexture()
    {
        IMFSample pSample;
        IMFTrackedSample pTrackedSample;
        HResult hr;

        // Create the video sample. This function returns an IMFTrackedSample per MSDN
        hr = MFExtern.MFCreateVideoSampleFromSurface(null, out pSample);
        MFError.ThrowExceptionForHR(hr);

        // Query the IMFSample to see if it implements IMFTrackedSample
        pTrackedSample = pSample as IMFTrackedSample;
        if(pTrackedSample == null)
        {
            // Throw an exception if we didn't get an IMFTrackedSample
            // but this shouldn't happen in practice.
            throw new InvalidCastException("MFCreateVideoSampleFromSurface returned a sample that did not implement IMFTrackedSample");
        }

        // Use our own class to allocate a texture
        SharpDX.Direct3D11.Texture2D availableTexture = AllocateTexture();
        // Convert the texture's native ID3D11Texture2D pointer into
        // an IUnknown (represented as as System.Object)
        object texNativeObject = Marshal.GetObjectForIUnknown(availableTexture.NativePointer);

        // Create the media buffer from the texture
        IMFMediaBuffer p2DBuffer;
        hr = MFExtern.MFCreateDXGISurfaceBuffer(s_IID_ID3D11Texture2D, texNativeObject, 0, false, out p2DBuffer);
        // Release the object-as-IUnknown we created above
        COMBase.SafeRelease(texNativeObject);
        // If media buffer creation failed, throw an exception
        MFError.ThrowExceptionForHR(hr);

        // Set the owning instance of this class as the allocator
        // for IMFTrackedSample to notify when the sample is released
        pTrackedSample.SetAllocator(this, null);

        // Attach the created buffer to the sample
        pTrackedSample.AddBuffer(p2DBuffer);

        return pTrackedSample;
    }

    // This is public so any textures you allocate but don't make IMFSamples 
    // out of can be returned to the allocator manually.
    public void ReturnFreeTexture(SharpDX.Direct3D11.Texture2D freeTexture)
    {
        m_freeStack.Push(freeTexture);
    }

    // IMFAsyncCallback.GetParameters
    // This is allowed to return E_NOTIMPL as a way of specifying
    // there are no special parameters.
    public HResult GetParameters(out MFAsync pdwFlags, out MFAsyncCallbackQueue pdwQueue)
    {
        pdwFlags = MFAsync.None;
        pdwQueue = MFAsyncCallbackQueue.Standard;
        return HResult.E_NOTIMPL;
    }

    public HResult Invoke(IMFAsyncResult pResult)
    {
        object pUnkObject;
        IMFSample pSample = null;
        IMFMediaBuffer pBuffer = null;
        IMFDXGIBuffer pDXGIBuffer = null;

        // Get the IUnknown out of the IMFAsyncResult if there is one
        HResult hr = pResult.GetObject(out pUnkObject);
        if(Succeeded(hr))
        {
            pSample = pUnkObject as IMFSample;
        }

        if(pSample != null)
        {
            // Based on your implementation, there should only be one 
            // buffer attached to one sample, so we can always grab the
            // first buffer. You could add some error checking here to make
            // sure the sample has a buffer count that is 1.
            hr = pSample.GetBufferByIndex(0, out pBuffer);
        }

        if(Succeeded(hr))
        {
            // Query the IMFMediaBuffer to see if it implements IMFDXGIBuffer
            pDXGIBuffer = pBuffer as IMFDXGIBuffer;
        }

        if(pDXGIBuffer != null)
        {
           // Got an IMFDXGIBuffer, so we can extract the internal 
           // ID3D11Texture2D and make a new SharpDX.Texture2D wrapper.
           hr = pDXGIBuffer.GetResource(s_IID_ID3D11Texture2D, out pUnkObject);
        }

        if(Succeeded(hr))
        {
           // If we got here, pUnkObject is the native D3D11 Texture2D as
           // a System.Object, but it's unlikely you have an interface 
           // definition for ID3D11Texture2D handy, so we can't just cast
           // the object to the proper interface.

           // Happily, SharpDX supports wrapping System.Object within
           // SharpDX.ComObject which makes things pretty easy.
           SharpDX.ComObject comWrapper = new SharpDX.ComObject(pUnkObject);

           // If this doesn't work, or you're using something like SlimDX
           // which doesn't support object wrapping the same way, the below
           // code is an alternative way.
           /*
           IntPtr pD3DTexture2D = Marshal.GetIUnknownForObject(pUnkObject);
           // Create your wrapper object here, like this for SharpDX
           SharpDX.ComObject comWrapper = new SharpDX.ComObject(pD3DTexture2D);
           // or like this for SlimDX
           SlimDX.Direct3D11.Texture2D.FromPointer(pD3DTexture2D);
           Marshal.Release(pD3DTexture2D);
           */

           // You might need to query comWrapper for a SharpDX.DXGI.Resource
           // first, then query that for the SharpDX.Direct3D11.Texture2D.
           SharpDX.Direct3D11.Texture2D texture = comWrapper.QueryInterface<SharpDX.Direct3D11.Texture2D>();
           if(texture != null)
           {
               // Now you can add "texture" back to the allocator's free list
               ReturnFreeTexture(texture);
           }
        }
    }
}


Setting MF_SA_D3D_AWARE关于 Sink Writer 输入媒体类型

我不认为这会造成不好的结果HRESULT你得到了,但无论如何这都不是正确的做法。MF_SA_D3D_AWARE(及其 DX11 对应项,MF_SA_D3D11_AWARE)是由设置的属性IMFTransform对象通知您该变换分别支持通过 DX9 或 DX11 的图形加速。无需在 Sink Writer 的输入媒体类型上设置此项。


No SafeRelease on texNativeObject

我建议打电话COMBase.SafeRelease() on texNativeObject否则你可能会泄漏内存。否则,您将不必要地延长该 COM 对象的生命周期,直到 GC 为您清理引用计数为止


不必要的铸造

这是上面代码的一部分:

buffer = MFVideoEncoderST.ReinterpretCast<IMF2DBuffer,IMFMediaBuffer>(p2Dbuffer);
int length=0;
if (Succeeded(hr)) hr = (int)p2Dbuffer.GetContiguousLength(out length);
if (Succeeded(hr)) hr = (int)buffer.SetCurrentLength(length);

我不确定你的是什么ReinterpretCast函数正在做,但是如果你do需要执行一个QueryInterface在 C# 中进行样式转换,您可以使用as运算符或常规演员。

// pMediaBuffer is of type IMFMediaBuffer and has been created elsewhere
IMF2DBuffer p2DBuffer = pMediaBuffer as IMF2DBuffer;
if(p2DBuffer != null)
{
    // pMediaBuffer is an IMFMediaBuffer that also implements IMF2DBuffer
}
else
{
    // pMediaBuffer does not implement IMF2DBuffer
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MF SinkWriter 写入样本失败 的相关文章

  • 访问私人成员[关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 通过将类的私有成员转换为 void 指针 然后转换为结构来访问类的私有成员是否合适 我认为我无权修改包含我需要访问的数据成员的类 如果不道德 我
  • 是否可以强制 XMLWriter 将元素写入单引号中?

    这是我的代码 var ptFirstName tboxFirstName Text writer WriteAttributeString first ptFirstName 请注意 即使我使用 ptFirstName 也会以双引号结束 p
  • Qt-Qlist 检查包含自定义类

    有没有办法覆盖加载自定义类的 Qt QList 的比较机制 即在 java 中你只需要重写一个比较方法 我有一个带有我的自定义类模型的 QList QList
  • 如何避免情绪低落?

    我有一个实现状态模式每个状态处理从事件队列获取的事件 根据State因此类有一个纯虚方法void handleEvent const Event 事件继承基础Event类 但每个事件都包含其可以是不同类型的数据 例如 int string
  • C++ 子字符串返回错误结果

    我有这个字符串 std string date 20121020 我正在做 std cout lt lt Date lt lt date lt lt n std cout lt lt Year lt lt date substr 0 4 l
  • 如何忽略“有符号和无符号整数表达式之间的比较”?

    谁能告诉我必须使用哪个标志才能使 gcc 忽略 有符号和无符号整数表达式之间的比较 警告消息 gcc Wno sign compare 但你确实应该修复它警告你的比较
  • WPF 中的调度程序和异步等待

    我正在尝试学习 WPF C 中的异步编程 但我陷入了异步编程和使用调度程序的困境 它们是不同的还是在相同的场景中使用 我愿意简短地回答这个问题 以免含糊不清 因为我知道我混淆了 WPF 中的概念和函数 但还不足以在功能上正确使用它 我在这里
  • 指针问题(仅在发布版本中)

    不确定如何描述这一点 但我在这里 由于某种原因 当尝试创建我的游戏的发布版本进行测试时 它的敌人创建方面不起作用 Enemies e level1 3 e level1 0 Enemies sdlLib 500 2 3 128 250 32
  • C 预处理器库

    我的任务是开发源分析工具C程序 并且我需要在分析本身之前预处理代码 我想知道什么是最好的图书馆 我需要一些重量轻 便于携带的东西 与其推出自己的 为什么不使用cpp这是的一部分gcc suite http gcc gnu org onlin
  • WPF TabControl,用C#代码更改TabItem的背景颜色

    嗨 我认为这是一个初学者的问题 我搜索了所有相关问题 但所有这些都由 xaml 回答 但是 我需要的是后台代码 我有一个 TabControl 我需要设置其项目的背景颜色 我需要在选择 取消选择和悬停时为项目设置不同的颜色 非常感谢你的帮助
  • 如何返回 json 结果并将 unicode 字符转义为 \u1234

    我正在实现一个返回 json 结果的方法 例如 public JsonResult MethodName Guid key var result ApiHelper GetData key Data is stored in db as v
  • 如何将图像路径保存到Live Tile的WP8本地文件夹

    我正在更新我的 Windows Phone 应用程序以使用新的 WP8 文件存储 API 本地文件夹 而不是 WP7 API 隔离存储文件 旧的工作方法 这是我如何成功地将图像保存到 共享 ShellContent文件夹使用隔离存储文件方法
  • 从路径中获取文件夹名称

    我有一些路c server folderName1 another name something another folder 我如何从那里提取最后一个文件夹名称 我尝试了几件事 但没有成功 我只是不想寻找最后的 然后就去休息了 Thank
  • clang 实例化后静态成员初始化

    这样的代码可以用 GCC 编译 但 clang 3 5 失败 include
  • C++ 复制初始化和直接初始化,奇怪的情况

    在继续阅读本文之前 请阅读在 C 中 复制初始化和直接初始化之间有区别吗 https stackoverflow com questions 1051379 is there a difference in c between copy i
  • 需要哪个版本的 Visual C++ 运行时库?

    microsoft 的最新 vcredist 2010 版 是否包含以前的版本 2008 SP1 和 2005 SP1 还是我需要安装全部 3 个版本 谢谢 你需要所有这些
  • 控制到达非 void 函数末尾 -wreturn-type

    这是查找四个数字中的最大值的代码 include
  • 在 Dynamics CRM 插件中访问电子邮件发件人地址

    我正在编写一个 Dynamics CRM 2011 插件 该插件挂钩到电子邮件实体的更新后事件 阶段 40 pipeline http msdn microsoft com en us library gg327941 aspx 并且在此阶
  • 限制C#中的并行线程数

    我正在编写一个 C 程序来生成并通过 FTP 上传 50 万个文件 我想并行处理4个文件 因为机器有4个核心 文件生成需要更长的时间 是否可以将以下 Powershell 示例转换为 C 或者是否有更好的框架 例如 C 中的 Actor 框
  • 使用 libcurl 检查 SFTP 站点上是否存在文件

    我使用 C 和 libcurl 进行 SFTP FTPS 传输 在上传文件之前 我需要检查文件是否存在而不实际下载它 如果该文件不存在 我会遇到以下问题 set up curlhandle for the public private ke

随机推荐

  • Java:使用itext读取PDF书签名称

    我正在处理包含多个文档的单个 PDF 每个文档都有一个书签 我需要读取我正在构建的调节应用程序的书签名称 下面的代码对我不起作用 我试图将书签名称放入title细绳 有人可以提供任何指导吗 非常感谢 PdfReader reader new
  • 防止 QScintilla 中触发键盘快捷键(示例代码)

    我想防止在 QScintilla 小部件中编辑代码时触发应用程序键盘快捷键 就像普通的 QLineEdit 字段不会触发一样 在下面的可执行示例代码中 无法在 QScintilla 小部件中键入空格 因为空格键已设置为快捷方式 但在 QLi
  • 使用 C# 将字符串表达式转换为整数值[重复]

    这个问题在这里已经有答案了 抱歉 如果这个问题已经得到解答 但我没有找到合适的答案 我在 C 中有一个字符串表达式 需要将其转换为 int 或十进制值 例如 string strExp 10 20 30 输出应该是 60 我该怎么办 Fwi
  • 斯威夫特||返回一个可由 API 调用中的其他方法使用的类

    我正在从移动应用程序调用 HERE Weather API 并且需要将当前天气作为对象返回 以便其他方法可以在给定时间段 例如 30 分钟更新间隔 内使用该信息 我根据这个网站对异步调用有了一个粗略的了解https fluffy es re
  • RestEASY 和 Jackson 不兼容 - NoSuchMethodException

    我将我的项目从JBoss AS 7 2 to 野蝇8 0经过一段时间的版本更新后 我不知道如何解决RestEASY and Jackson不兼容 In JBoss AS 7 2 I used RestEASY 3 0 6 Final and
  • 添加文本后缀

    我目前有很多这样的输入
  • 复选框的默认控件模板

    我找不到默认的 WPFControlTemplate for a CheckBox 有谁知道如何找到它吗 我所能找到的就是MSDN 上的 SilverLight 默认复选框模板 MSDN 有一个用于 WPF 复选框的自定义控件模板使用 X
  • iPhone动画帧速率和帧数

    我正在开发一个应用程序 客户想要为大图像 305x332 制作动画 客户希望在 1 75 秒内循环播放 50 帧动画 我发现该应用程序在进行如此多的处理时速度非常慢 启动 触摸响应和关闭都很慢 在 iPhone 本身上 该应用程序经常会崩溃
  • Angular CDK 拖放绝对定位元素而不跳转

    我正在尝试使用 CDK 中的 Angular Drag Drop 来实现带有可拖动元素的基本侧边栏 用户可以将它们拖放到 内容 区域中的任何位置 这意味着 元素最终应该是绝对定位的 并且应该能够存在于用户想要的任何地方 包括相互重叠 我正在
  • 如何在 VBScript 中循环?

    我想知道如何 或者甚至知道是否可以在 VBScript 中的循环内循环 从逻辑上讲 世界是这样运作的 Do until y 5 msgbox msgbox 1 loop test Do Until z 5 msgbox msgbox 2 l
  • R 中的过滤和显示过滤数据摘要的奇怪之处

    我有一个使用 R 中的 CSV 库加载的数据框 例如 mySheet lt read csv Table csv sep 我现在可以打印该 mySheet 对象的摘要 summary mySheet 它将向我显示每一列的摘要 例如 名为 D
  • go中如何导入本地包?

    我是新来的 正在处理我想要本地化的示例代码 在原来的main go导入声明是 import log net http github com foo bar myapp common github com foo bar myapp rout
  • 节点服务器在解析 JSON 时崩溃

    看起来我的节点服务器死掉了parseJSON 查看日志 最后一条消息是 解析之前 并且从未打印 解析之后 奇怪的是 我用 try catch 包装了 JSON pars 所以我不确定它是如何导致服务器崩溃的 有什么想法吗 logger pr
  • glmmLasso 错误和警告

    我正在尝试使用 glmmLasso 在广义线性混合模型中执行变量选择 但出现了一个我无法解决的错误和警告 数据集不平衡 一些参与者 PTNO 拥有比其他参与者更多的样本 无缺失数据 我的因变量是二进制的 所有其他变量 除了 ID 变量 PT
  • 如何从Google Play商店获取应用市场版本信息?

    如何从 Google Play 商店获取应用程序版本信息 以便在 Play 商店应用程序更新时提示用户强制 建议更新应用程序 即用户使用旧版本应用程序时 我已经经历过android 市场 api这不是官方方式 并且还需要授权登录来自谷歌的身
  • 类将数据成员存储在顺序内存中?

    这个问题的简短版本 指向类的第一个数据成员的指针是否会导致指向其所有数据成员的指针 讨论 我正在阅读一些示例代码 这很有趣 当一个特定的函数 在本例中是glUniformMatrix4fvOpenGL 中的 C 函数 将数组作为参数 这是使
  • Javascript 模式:条件事件处理程序

    给定例如某种类实例具有状态 例如 活动 非活动 该实例还附加了一个点击事件 例如一个链接 但事件处理程序根据实例的状态执行不同的操作 伪代码 IF instance state IS active AND link is clicked T
  • 在 iOS 上通过 FCM 使用丰富推送通知中的数据

    我的问题可能很糟糕 但我在任何地方都找不到任何答案 我迷路了 所以我想在 iOS 10 中显示带有漂亮图像的丰富通知 为此 我使用 FCM 和 UNNotificationServiceExtension 如果我理解正确的话 它应该获取数据
  • 无法共同创建对象/找不到绰号 |雅各布

    当创建一个ActiveXComponent使用 JACOB 我收到以下错误 com jacob com ComFailException Can t co create object at com jacob com Dispatch cr
  • MF SinkWriter 写入样本失败

    我正在尝试使用 MediaFoundation 将 ID3D11Texture2D 编码为 mp4 下面是我当前的代码 初始化接收器写入器 private int InitializeSinkWriter String outputFile