You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.0 KiB

  1. // Copyright (c) 2021 Ximalaya Speech Team (Xiang Lyu)
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <grpcpp/ext/proto_server_reflection_plugin.h>
  15. #include <grpcpp/grpcpp.h>
  16. #include <grpcpp/health_check_service_interface.h>
  17. #include "gflags/gflags.h"
  18. #include "decoder/params.h"
  19. #include "grpc/grpc_server.h"
  20. DEFINE_int32(port, 10086, "grpc listening port");
  21. DEFINE_int32(workers, 4, "grpc num workers");
  22. using grpc::Server;
  23. using grpc::ServerBuilder;
  24. int main(int argc, char* argv[]) {
  25. gflags::ParseCommandLineFlags(&argc, &argv, false);
  26. google::InitGoogleLogging(argv[0]);
  27. auto decode_config = wenet::InitDecodeOptionsFromFlags();
  28. auto feature_config = wenet::InitFeaturePipelineConfigFromFlags();
  29. auto decode_resource = wenet::InitDecodeResourceFromFlags();
  30. wenet::GrpcServer service(feature_config, decode_config, decode_resource);
  31. grpc::EnableDefaultHealthCheckService(true);
  32. grpc::reflection::InitProtoReflectionServerBuilderPlugin();
  33. ServerBuilder builder;
  34. std::string address("0.0.0.0:" + std::to_string(FLAGS_port));
  35. builder.AddListeningPort(address, grpc::InsecureServerCredentials());
  36. builder.RegisterService(&service);
  37. builder.SetSyncServerOption(ServerBuilder::SyncServerOption::NUM_CQS,
  38. FLAGS_workers);
  39. std::unique_ptr<Server> server(builder.BuildAndStart());
  40. LOG(INFO) << "Listening at port " << FLAGS_port;
  41. server->Wait();
  42. google::ShutdownGoogleLogging();
  43. return 0;
  44. }