public MyUserControl() { InitializeComponent(); filter = new MyFilter(); filter.LButtonScroll += new MyFilter.LBUTTONSCROLLDELEGATE(filter_LButtonScroll); Application.AddMessageFilter(filter); }
public void TestFilter_ByText_Filtered1() { //Arrange MyMessage message; List <MyMessage> myReceivedMessages = new List <MyMessage>(); MyFilter filter = new MyFilter(); for (int i = 0; i < 50; i++) { message = new MyMessage(); if (message.Text != null) { myReceivedMessages.Add(message); } } string expectedText = "ao"; //Act List <MyMessage> myFilteredMessages = filter.FilterbyText(myReceivedMessages, expectedText); List <MyMessage> expectedMessages = (from m in myReceivedMessages where m.Text.Contains(expectedText) select m).ToList(); //Assert Assert.IsTrue(expectedMessages.SequenceEqual(myFilteredMessages)); }
public void TestFilter_OrLogic_Filtered() { //Arrange MyMessage message; List <MyMessage> myReceivedMessages = new List <MyMessage>(); MyFilter filter = new MyFilter(); for (int i = 0; i < 50; i++) { message = new MyMessage(); if (message.Text != null) { myReceivedMessages.Add(message); } } string expectedSubscriber = "+380939873546"; string expectedText = "ao"; DateTime fromDate = DateTime.Now.AddDays(-1); DateTime toDate = DateTime.Now.AddDays(1); //Act List <MyMessage> myFilteredMessages = filter.FilterOr(myReceivedMessages, expectedSubscriber, expectedText, fromDate, toDate); List <MyMessage> myExpectedMessages = (from m in myReceivedMessages where (m.User == expectedSubscriber || m.Text.Contains(expectedText) || (fromDate <= m.ReceivingTime && toDate > m.ReceivingTime)) select m).ToList(); //Assert Assert.IsTrue(myExpectedMessages.SequenceEqual(myFilteredMessages)); }
public void TestFilter_ByUser_Filtered() { //Arrange MyMessage message; List <MyMessage> myReceivedMessages = new List <MyMessage>(); MyFilter filter = new MyFilter(); for (int i = 0; i < 50; i++) { message = new MyMessage(); if (message.Text != null) { myReceivedMessages.Add(message); } } string expectedSubscriber = "+380939873546"; //Act List <MyMessage> myFilteredMessages = filter.FilterbyUser(myReceivedMessages, expectedSubscriber); List <string> selectedUsers = (from m in myFilteredMessages select m.User).ToList(); //Assert /* Assert.IsTrue(selectedUsers.Distinct().Count() <= 1); * if (selectedUsers.Distinct().Count()==1) { * Assert.AreEqual(expectedSubscriber, selectedUsers[0]); * }*/ Assert.IsTrue((selectedUsers.Distinct().Count() == 0) || ((selectedUsers.Distinct().Count() == 1) && (expectedSubscriber.Equals(selectedUsers[0])))); }
public void TestFilter_Bydate_Filtered() { //Arrange MyMessage message; List <MyMessage> myReceivedMessages = new List <MyMessage>(); MyFilter filter = new MyFilter(); for (int i = 0; i < 50; i++) { message = new MyMessage(); if (message.Text != null) { myReceivedMessages.Add(message); } } DateTime fromDate = DateTime.Now.AddDays(-1); DateTime toDate = DateTime.Now.AddDays(1); //Act List <MyMessage> myFilteredMessages = filter.FilterbyDate(myReceivedMessages, fromDate, toDate); List <MyMessage> expectedMessages = (from m in myReceivedMessages where m.ReceivingTime >= fromDate && m.ReceivingTime < toDate select m).ToList(); //Assert Assert.IsTrue(expectedMessages.SequenceEqual(myFilteredMessages)); }
private void Form1_Load(object sender, EventArgs e) { button5.Visible = false; mf = new MyFilter(); mf.MouseMoved += Mf_MouseMoved; mf.ThreeSecondWithoutMouseMove += Mf_ThreeSecondWithoutMouseMove; Application.AddMessageFilter(mf); }
static void Main() { MyFilter m = new MyFilter(); System.Console.WriteLine(foo1 <K> (m).Count); MyBFilter mb = new MyBFilter(); System.Console.WriteLine(foo1 <B> (mb).Count); }
static void Test1() { MyFilter m = new MyFilter(); System.Console.WriteLine(foo1 <K>(m).Length); MyBFilter mb = new MyBFilter(); System.Console.WriteLine(foo1 <B>(mb).Length); }
public void CustomFilterTest() { TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 8, 0, throwIfOtherPlatform: false); TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 11, throwIfOtherPlatform: false); MyFilter filter = new MyFilter(); Assert.NotNull(filter); filter.Input = 10; Assert.AreEqual(10, filter.Input); }
public void CustomFilterTest() { if (!TestRuntime.CheckSystemAndSDKVersion(8, 0)) { Assert.Inconclusive("Custom filters require iOS8+"); } MyFilter filter = new MyFilter(); Assert.NotNull(filter); filter.Input = 10; Assert.AreEqual(10, filter.Input); }
//public override void PrePlanRun() //{ // // This method is called on all TestSteps at the START of TestPlan execution. // // If no setup code is needed, this method can be removed. // base.PrePlanRun(); //} public override void Run() { // The Run method is where the main execution logic of a TestStep exists. // This is a required method. try { // Setup instrument. MyGenerator.SetInputData(InputData); // Setup DUT. MyFilter.WindowSize = WindowSize; // Execute logic for DUT and handle data from DUT. ReadOnlyOutputData = MyFilter.CalcMovingAverage(InputData); // Check to see if limit checking is enabled. If so, Upgrade the verdict. if (LimitCheckEnabled) { // The Verdict is used by TAP to convey the general execution result of a Test Step. UpgradeVerdict(ReadOnlyOutputData.Max() >= MaxAmplitude ? Verdict.Fail : Verdict.Pass); } else { // All Test Steps have a standard Log object (inherited from the base class) // that can be used to write messages to the run log and the session log. Log.Debug("Limit checking was not enabled. This is why the verdict is inconclusive."); UpgradeVerdict(Verdict.Inconclusive); } // Different log message types can be used based on what is being written. Log.Info("The DUT comment is {0}", MyFilter.Comment); // All Test Steps also contain a Results object. Results are store by calling Publish or PublishTable. Results.PublishTable("Inputs Versus Moving Average", new List <string>() { "Input Values", "Output Values" }, InputData, ReadOnlyOutputData); } catch (Exception ex) { Log.Error(ex.Message); // The verdict can be set more than once in a Test Step. // UpgradeVerdict sets the current verdict to the more serious verdict. // If the new Verdict is not more severe, the original setting will be kept. UpgradeVerdict(Verdict.Error); } }
public formDriversList() { InitializeComponent(); driverList = DriverList.getInstance(); btnAdd.Visible = User.IsFullAccess(); btnDelete.Visible = User.IsFullAccess(); _searcher = new SearchInDgv(_dgvDrivers); _myStatusStrip = new MyStatusStrip(_dgvDrivers, statusStrip1); _myFilter = MyFilter.GetInstanceDrivers(); _myFilter.Fill(_dgvDrivers, _myStatusStrip, this); }
protected void Page_Load(object sender, EventArgs e) { ASPxGridView1.InitSettings(); ASPxGridView1.InitEditForm(); ASPxGridView1.RowInserting += ASPxGridView1_RowInserting; ASPxGridView1.RowDeleting += ASPxGridView1_RowDeleting; ASPxGridView1.RowUpdating += ASPxGridView1_RowUpdating; ASPxGridView1.RowValidating += ASPxGridView1_RowValidating; if (!IsPostBack) { var filter = new MyFilter(); SetFilter(filter); } // Bind(); Query(sender, e); }
public void FormatAndFilter() { FormatDelegate currentFormat; currentFormat = Format.GetFormatType(comboBox1); List <MyMessage> listToDisplay = new List <MyMessage>(); listToDisplay = myReceivedMessages; MyFilter filter = new MyFilter(); object selectedUser = new object(); if (comboBox2.Created) { selectedUser = MyMobile.SMSProvider.selectUser(comboBox2); } listToDisplay = filter.ApplyFilter(filter, myReceivedMessages, selectedUser, textBox1.Text, dateTimePicker1.Value, dateTimePicker2.Value, checkBoxAndLogic, checkBoxOrLogic); Format.ShowMessages(MessageListView, listToDisplay, currentFormat); }
public void TestFilter_ByText_Filtered2() { //Arrange MyMessage message; List <MyMessage> myReceivedMessages = new List <MyMessage>(); MyFilter filter = new MyFilter(); for (int i = 0; i < 50; i++) { message = new MyMessage(); if (message.Text != null) { myReceivedMessages.Add(message); } } string expectedText = "ao"; //Act List <MyMessage> myFilteredMessages = filter.FilterbyText(myReceivedMessages, expectedText); List <string> selectedMessages = (from m in myFilteredMessages select m.Text).ToList(); //Assert if (selectedMessages.Count() > 0) { foreach (string m in selectedMessages) { Assert.IsTrue(m.Contains(expectedText)); } } else { List <string> unselectedMessages = (from m in myReceivedMessages select m.Text).ToList(); foreach (string m in unselectedMessages) { Assert.IsFalse(m.Contains(expectedText)); } } }
public MainForm(ICarForm carForm) { _carForm = carForm; InitializeComponent(); _carList = CarList.getInstance(); _mainStatus = MainStatus.getInstance(); _mainStatus.StatusChanged += statusChanged; _mainStatus.StatusChanged += SetWindowHeaderText; _mainStatus.StatusChanged += ConfigContextMenu; _dgvMain = new MainDGV(_dgvCar); _seacher = new SearchInDgv(_dgvCar); _myStatusStrip = new MyStatusStrip(_dgvCar, statusStrip1); _myFilter = MyFilter.GetInstanceCars(); _myFilter.Fill(_dgvCar, _myStatusStrip, this); }
public async Task Should_support_interaction_between_filters() { var myFilter = new MyFilter(); IPipeRouter router = new PipeRouter(); IPipe <InputContext> pipe = Pipe.New <InputContext>(cfg => { cfg.UseConcurrencyLimit(10, router); cfg.UseCircuitBreaker(cb => { cb.ActiveThreshold = 5; cb.TrackingPeriod = TimeSpan.FromSeconds(60); cb.TripThreshold = 25; cb.ResetInterval = TimeSpan.FromSeconds(30); cb.Router = router; }); cfg.UseRetry(x => x.Immediate(1)); cfg.UseFilter(myFilter); }); myFilter.Throw = true; router.ConnectPipe(Pipe.New <EventContext <CircuitBreakerOpened> >(x => x.UseFilter(new MyController(router)))); await Task.WhenAll(Enumerable.Range(0, 140).Select(async index => { try { await pipe.Send(new InputContext("Hello")); } catch (Exception ex) { await Console.Out.WriteLineAsync($"{DateTime.Now:mm:ss:fff} - Faulted: {ex.Message}"); } })); }
private ToolStripMenuItem CreateFilter() { ToolStripMenuItem item = CreateItem("Фильтр по значению этого поля"); item.Click += delegate { DataGridView dgv = _dgvMain.GetDGV(); if (dgv.CurrentCell == null) { return; } string columnName = dgv.Columns[dgv.CurrentCell.ColumnIndex].HeaderText; Point point = new Point(dgv.CurrentCell.ColumnIndex, dgv.CurrentCell.RowIndex); MyFilter myFilter = (dgv.Name == "_dgvCar") ? MyFilter.GetInstanceCars() : MyFilter.GetInstanceDrivers(); myFilter.SetFilterValue(string.Concat(columnName, ":"), point); }; return(item); }
private void timer_Tick(object sender, EventArgs e) { //string text = "New SMS received"; //from lab3 MyMessage message = new MyMessage(); FormatDelegate currentFormat; currentFormat = Format.FormatType[comboBox1.SelectedIndex]; //MyMobile.SMSProvider.ReceiveSMS(Format.OnSMSReceived(message.ToString(), currentFormat)); //lab4, task 0, variant 1 if (message.Text != null) { myReceivedMessages.Add(message); if (!comboBox2.Items.Contains(message.User)) { comboBox2.Items.Add(message.User); } } List <MyMessage> listToDisplay = new List <MyMessage>(); listToDisplay = myReceivedMessages; MyFilter filter = new MyFilter(); if (checkBoxAndLogic.Checked == true) { listToDisplay = filter.FilterAnd(myReceivedMessages, comboBox2.SelectedItem, textBox1.Text, dateTimePicker1.Value, dateTimePicker2.Value); } if (checkBoxOrLogic.Checked == true) { listToDisplay = filter.FilterOr(myReceivedMessages, comboBox2.SelectedItem, textBox1.Text, dateTimePicker1.Value, dateTimePicker2.Value); } ShowMessages(listToDisplay, currentFormat); MyMobile.SMSProvider.ReceiveSMS(message); }
public void TestStatementFilter() { _epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean_A)); _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean_B)); // one statement exists before the data flow var stmt = _epService.EPAdministrator.CreateEPL("select id from SupportBean_B"); _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " + "create schema AllObjects Object," + "EPStatementSource -> thedata<AllObjects> {} " + "DefaultSupportCaptureOp(thedata) {}"); var captureOp = new DefaultSupportCaptureOp(); var options = new EPDataFlowInstantiationOptions(); var myFilter = new MyFilter(); options.ParameterProvider(new DefaultSupportGraphParamProvider(Collections.SingletonDataMap("statementFilter", myFilter))); options.OperatorProvider(new DefaultSupportGraphOpProvider(captureOp)); var df = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); df.Start(); _epService.EPRuntime.SendEvent(new SupportBean_B("B1")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "B1" }); _epService.EPAdministrator.CreateEPL("select TheString, IntPrimitive from SupportBean"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "TheString,IntPrimitive".Split(','), new Object[] { "E1", 1 }); var stmtTwo = _epService.EPAdministrator.CreateEPL("select id from SupportBean_A"); _epService.EPRuntime.SendEvent(new SupportBean_A("A1")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "A1" }); stmtTwo.Stop(); _epService.EPRuntime.SendEvent(new SupportBean_A("A2")); Thread.Sleep(50); Assert.AreEqual(0, captureOp.GetCurrent().Length); stmtTwo.Start(); _epService.EPRuntime.SendEvent(new SupportBean_A("A3")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "A3" }); _epService.EPRuntime.SendEvent(new SupportBean_B("B2")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "B2" }); df.Cancel(); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean_A("A1")); _epService.EPRuntime.SendEvent(new SupportBean_B("B3")); Assert.AreEqual(0, captureOp.GetCurrent().Length); }
public MvxFilteringBindableListAdapter(Context context) : base(context) { Filter = new MyFilter(this); }
} // MyIPFilterChannelSink public void AddFilter(IPAddress mask, IPAddress ipAddress1) { MyFilter f = new MyFilter(mask, ipAddress1); myFilterSet.Add(f); }
public MvxFilteringAdapter(Context context) : base(context) { ReturnSingleObjectFromGetItem = true; Filter = new MyFilter(this); }
public void SetUp() { filter = new MyFilter(); }
public MvxFilteringAdapter(Context context, IMvxAndroidBindingContext bindingContext) : base(context, bindingContext) { ReturnSingleObjectFromGetItem = true; Filter = new MyFilter(this); }
public void Run(RegressionEnvironment env) { // one statement exists before the data flow env.CompileDeploy("select Id from SupportBean_B"); env.CompileDeploy( "@Name('flow') create dataflow MyDataFlowOne " + "create schema AllObjects as System.Object," + "EPStatementSource -> thedata<AllObjects> {} " + "DefaultSupportCaptureOp(thedata) {}"); var captureOp = new DefaultSupportCaptureOp(env.Container.LockManager()); var options = new EPDataFlowInstantiationOptions(); var myFilter = new MyFilter(); options.WithParameterProvider( new DefaultSupportGraphParamProvider( Collections.SingletonMap<string, object>("statementFilter", myFilter))); options.WithOperatorProvider(new DefaultSupportGraphOpProvider(captureOp)); var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options); df.Start(); env.SendEventBean(new SupportBean_B("B1")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps( env.Container, captureOp.GetCurrentAndReset()[0], new [] { "Id" }, new object[] {"B1"}); env.CompileDeploy("select TheString, IntPrimitive from SupportBean"); env.SendEventBean(new SupportBean("E1", 1)); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps( env.Container, captureOp.GetCurrentAndReset()[0], new [] { "TheString","IntPrimitive" }, new object[] {"E1", 1}); env.CompileDeploy("@Name('s2') select Id from SupportBean_A"); env.SendEventBean(new SupportBean_A("A1")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps( env.Container, captureOp.GetCurrentAndReset()[0], new [] { "Id" }, new object[] {"A1"}); env.UndeployModuleContaining("s2"); env.SendEventBean(new SupportBean_A("A2")); Sleep(50); Assert.AreEqual(0, captureOp.Current.Length); env.CompileDeploy("@Name('s2') select Id from SupportBean_A"); env.SendEventBean(new SupportBean_A("A3")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps( env.Container, captureOp.GetCurrentAndReset()[0], new [] { "Id" }, new object[] {"A3"}); env.SendEventBean(new SupportBean_B("B2")); captureOp.WaitForInvocation(200, 1); EPAssertionUtil.AssertProps( env.Container, captureOp.GetCurrentAndReset()[0], new [] { "Id" }, new object[] {"B2"}); df.Cancel(); env.SendEventBean(new SupportBean("E1", 1)); env.SendEventBean(new SupportBean_A("A1")); env.SendEventBean(new SupportBean_B("B3")); Assert.AreEqual(0, captureOp.Current.Length); env.UndeployAll(); }
void SetFilter(MyFilter filter) { HiddenField1.Value = JsonConvert.SerializeObject(filter); }
public MyFilterInternal(MyFilter <T> parent, IObserver <T> observer) { _observer = observer; _parent = parent; }
unsafe static void Main(string[] args) { ffmpeg.RootPath = @"D:\cshapdemo\ConsoleApp1\ffmpeg"; var file1 = @"D:\cshapdemo\ConsoleApp1\会不会.mp3"; var file2 = @"D:\cshapdemo\ConsoleApp1\无人之岛-任然.mp3"; Openfile openfile1 = new Openfile(); Openfile openfile2 = new Openfile(); openfile1.open(file1); openfile2.open(file2); Openfile outfile = new Openfile(); outfile.OpenFileOutput(@"D:\cshapdemo\ConsoleApp1\3.mp3"); Console.WriteLine("eee"); AVAudioFifo *aVAudioFifo1 = ffmpeg.av_audio_fifo_alloc( openfile1._pCodecContext->sample_fmt, openfile1._pCodecContext->channels, 30 * openfile1._pCodecContext->frame_size); AVAudioFifo *aVAudioFifo2 = ffmpeg.av_audio_fifo_alloc( openfile2._pCodecContext->sample_fmt, openfile2._pCodecContext->channels, 30 * openfile2._pCodecContext->frame_size); //打开输入输出文件 Console.WriteLine("aVAudioFifo2 "); // readFile(openfile1, aVAudioFifo1); //配置过滤器 AVFilterGraph * _filter_graph = null; AVFilterContext *_filter_ctx_src_spk = null; AVFilterContext *_filter_ctx_src_mic = null; AVFilterContext *_filter_ctx_sink = null; string filter_desc = "[in0][in1]amix=inputs=2[out]"; // InitFilter(_filter_graph, filter_desc, _filter_ctx_src_spk, _filter_ctx_src_mic, _filter_ctx_sink, openfile1, openfile2, outfile); MyFilter myFilter = new MyFilter(); myFilter.InitFilter(_filter_graph, filter_desc, _filter_ctx_src_spk, _filter_ctx_src_mic, _filter_ctx_sink, openfile1, openfile2, outfile); //Thread thread1 = new Thread(start: new ThreadStart(new My(openfile1, aVAudioFifo1).C)); // Thread thread2 = new Thread(start: new ThreadStart(new My(openfile2, aVAudioFifo2).C)); readFile(openfile1, aVAudioFifo1); readFile(openfile2, aVAudioFifo2); if (count == 2) { Console.WriteLine("2222222222222222222"); } int tmpFifoFailed = 0; int frame_count = 0; while (true) { AVFrame *pFrame_spk = ffmpeg.av_frame_alloc(); AVFrame *pFrame_mic = ffmpeg.av_frame_alloc(); AVPacket packet_out; int got_packet_ptr = 0; int fifo_spk_size = ffmpeg.av_audio_fifo_size(aVAudioFifo1); int fifo_mic_size = ffmpeg.av_audio_fifo_size(aVAudioFifo2); int frame_spk_min_size = openfile1._pFormatContext->streams[openfile1._streamIndex]->codecpar->frame_size; int frame_mic_min_size = openfile2._pFormatContext->streams[openfile2._streamIndex]->codecpar->frame_size; Console.WriteLine("fifo_spk_size:==" + fifo_spk_size); if (fifo_spk_size >= frame_spk_min_size && fifo_mic_size >= frame_mic_min_size) { tmpFifoFailed = 0; pFrame_spk->nb_samples = frame_spk_min_size; pFrame_spk->channel_layout = openfile1._pFormatContext->streams[openfile1._streamIndex]->codecpar->channel_layout; pFrame_spk->format = (int)openfile1._pFormatContext->streams[openfile1._streamIndex]->codec->sample_fmt; pFrame_spk->sample_rate = openfile1._pFormatContext->streams[openfile1._streamIndex]->codecpar->sample_rate; // pFrame_spk->format = 8; int ret = ffmpeg.av_frame_get_buffer(pFrame_spk, 0); if (ret < 0) { Console.WriteLine("av_frame_get_buffer pFrame_spk failed"); } pFrame_mic->nb_samples = frame_mic_min_size; pFrame_mic->channel_layout = openfile2._pFormatContext->streams[openfile2._streamIndex]->codecpar->channel_layout; pFrame_mic->format = (int)openfile2._pFormatContext->streams[openfile2._streamIndex]->codec->sample_fmt; //pFrame_mic->format = 4; pFrame_mic->sample_rate = openfile2._pFormatContext->streams[openfile2._streamIndex]->codecpar->sample_rate; ret = ffmpeg.av_frame_get_buffer(pFrame_mic, 0); if (ret < 0) { Console.WriteLine("av_frame_get_buffer pFrame_mic failed"); } int nSizeOfPerson = Marshal.SizeOf(pFrame_spk->data); //定义指针长度 IntPtr spkX = Marshal.AllocHGlobal(nSizeOfPerson); //定义指针 Marshal.StructureToPtr(pFrame_spk->data, spkX, true); //将结构体person转为personX指针 ret = ffmpeg.av_audio_fifo_read(aVAudioFifo1, (void **)spkX, frame_spk_min_size); //读取数据1 Thread.Sleep(1000); int nSizeOfPerson2 = Marshal.SizeOf(pFrame_mic->data); //定义指针长度 IntPtr spkX2 = Marshal.AllocHGlobal(nSizeOfPerson2); //定义指针 Marshal.StructureToPtr(pFrame_mic->data, spkX2, true); //将结构体person转为personX指针 ret = ffmpeg.av_audio_fifo_read(aVAudioFifo2, (void **)spkX2, frame_mic_min_size); //读取数据2 // Thread thread1 = new Thread(start:new ThreadStart(new My2(pFrame_mic, aVAudioFifo2).C)); // pFrame_spk->pts = ffmpeg.av_frame_get_best_effort_timestamp(pFrame_spk); // pFrame_mic->pts = ffmpeg.av_frame_get_best_effort_timestamp(pFrame_mic); _filter_ctx_src_spk = myFilter._filter_ctx_src_spk; _filter_ctx_src_mic = myFilter._filter_ctx_src_mic; _filter_ctx_sink = myFilter._filter_ctx_sink; ret = ffmpeg.av_buffersrc_add_frame(_filter_ctx_src_spk, pFrame_spk);//交给filter if (ret < 0) { Console.WriteLine("Mixer: failed to call av_buffersrc_add_frame (speaker)\n"); break; } ret = ffmpeg.av_buffersrc_add_frame(_filter_ctx_src_mic, pFrame_mic); if (ret < 0) { Console.WriteLine("Mixer: failed to call av_buffersrc_add_frame (mic)\n"); break; } //取出滤镜混合后的样本数据 //对数据进行编码后写入IO //关闭资源关闭io while (true) { AVFrame *pFrame_out = ffmpeg.av_frame_alloc(); ret = ffmpeg.av_buffersink_get_frame_flags(_filter_ctx_sink, pFrame_out, 0); if (ret < 0) { var bufferSize = 1024; var buffer = stackalloc byte[bufferSize]; ffmpeg.av_strerror(ret, buffer, (ulong)bufferSize); var message = Marshal.PtrToStringAnsi((IntPtr)buffer); Console.WriteLine("Mixer: failed to call av_buffersink_get_frame_flags\n" + message); break; } if (pFrame_out->data[0] != null) { ffmpeg.av_init_packet(&packet_out); packet_out.data = null; packet_out.size = 0; //ret=ffmpeg.avcodec_send_frame(outfile._pCodecContext, pFrame_out); //if (ret < 0) //{ // Console.WriteLine("Mixer: failed to call avcodec_send_frame pFrame_out \n"); // break; //} //ret=ffmpeg.avcodec_receive_packet(outfile._pCodecContext, &packet_out); //if (ret < 0) //{ // Console.WriteLine("Mixer: failed to call avcodec_send_frame packet_out \n"); // break; //} ret = ffmpeg.avcodec_encode_audio2(outfile._pCodecContext, &packet_out, pFrame_out, &got_packet_ptr); if (ret < 0) { Console.WriteLine("Mixer: failed to call avcodec_decode_audio4\n"); break; } if (got_packet_ptr > 0) { packet_out.stream_index = outfile._streamIndex; packet_out.pts = frame_count * outfile._pCodecContext->frame_size; packet_out.dts = packet_out.pts; packet_out.duration = outfile._pCodecContext->frame_size; packet_out.pts = ffmpeg.av_rescale_q_rnd(packet_out.pts, outfile._pCodecContext->time_base, outfile._pCodecContext->time_base, (AVRounding)(1 | 8192)); packet_out.dts = packet_out.pts; packet_out.duration = ffmpeg.av_rescale_q_rnd(packet_out.duration, outfile._pCodecContext->time_base, outfile._pCodecContext->time_base, (AVRounding)(1 | 8192)); frame_count++; ret = ffmpeg.av_interleaved_write_frame(outfile._pFormatContext, &packet_out); if (ret < 0) { Console.WriteLine("Mixer: failed to call av_interleaved_write_frame\n"); } Console.WriteLine("Mixer: write frame to file\n"); } ffmpeg.av_packet_unref(&packet_out); } ffmpeg.av_frame_free(&pFrame_out); Thread.Sleep(1000); } Console.WriteLine("tmpFifoFailed:" + tmpFifoFailed); } else { Console.WriteLine("else tmpFifoFailed:" + tmpFifoFailed); //=========================================================================== tmpFifoFailed++; if (tmpFifoFailed > 300) { break; } ffmpeg.av_frame_free(&pFrame_spk); ffmpeg.av_frame_free(&pFrame_mic); } } ffmpeg.av_write_trailer(outfile._pFormatContext); }